Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making string_proxy::operator==( string_proxy ) const to disambiguate #855

Merged
merged 2 commits into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") )
}
}