Skip to content

Commit

Permalink
Merge pull request #855 from romainfrancois/b-854
Browse files Browse the repository at this point in the history
making string_proxy::operator==( string_proxy ) const to disambiguate
  • Loading branch information
eddelbuettel committed May 27, 2018
2 parents 8c360a8 + 9c8562a commit 032d307
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
28 changes: 15 additions & 13 deletions inst/include/Rcpp/vector/string_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,33 @@ namespace internal{
std::for_each( begin(), end(), op );
}

bool operator==( const char* other){
bool operator==( const char* other) const {
return strcmp( begin(), other ) == 0 ;
}
bool operator!=( const char* other){
bool operator!=( const char* other) const {
return strcmp( begin(), other ) != 0 ;
}

bool operator==( const string_proxy& other){
template<template <class> class SP>
bool operator==( const string_proxy<STRSXP, SP>& other) const {
return strcmp( begin(), other.begin() ) == 0 ;
}
bool operator!=( const string_proxy& other){

template<template <class> class SP>
bool operator!=( const string_proxy<STRSXP,SP>& other) const {
return strcmp( begin(), other.begin() ) != 0 ;
}

bool operator==( SEXP other ) const {
return get() == other;
}

bool operator!=( SEXP other ) const {
return get() != other;
}
bool operator==( SEXP other ) const {
return get() == other;
}

bool operator!=( SEXP other ) const {
return get() != other;
}

private:
static std::string buffer ;
private:
static std::string buffer ;

} ;

Expand Down
18 changes: 18 additions & 0 deletions inst/unitTests/cpp/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,3 +868,21 @@ List ListNoProtect_crosspolicy(Vector<VECSXP, NoProtectStorage> data){
data2[0] = data[0];
return data2;
}

// [[Rcpp::export]]
bool CharacterVector_test_equality(CharacterVector x, CharacterVector y) {
if (x.length() != y.length()) {
return false;
}

return std::equal(x.begin(), x.end(), y.begin());
}

// [[Rcpp::export]]
bool CharacterVector_test_equality_crosspolicy(CharacterVector x, Vector<STRSXP,NoProtectStorage> y) {
if (x.length() != y.length()) {
return false;
}

return std::equal(x.begin(), x.end(), y.begin());
}
5 changes: 5 additions & 0 deletions inst/unitTests/runit.Vector.R
Original file line number Diff line number Diff line change
Expand Up @@ -772,4 +772,9 @@ if (.runThisTest) {
data2 <- ListNoProtect_crosspolicy(data)
checkEquals(data, data2)
}

test.CharacterVector_test_equality <- function(){
checkTrue( !CharacterVector_test_equality("foo", "bar") )
checkTrue( !CharacterVector_test_equality_crosspolicy("foo", "bar") )
}
}

0 comments on commit 032d307

Please sign in to comment.