Skip to content

Commit 032d307

Browse files
authored
Merge pull request #855 from romainfrancois/b-854
making string_proxy::operator==( string_proxy ) const to disambiguate
2 parents 8c360a8 + 9c8562a commit 032d307

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

inst/include/Rcpp/vector/string_proxy.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,31 +187,33 @@ namespace internal{
187187
std::for_each( begin(), end(), op );
188188
}
189189

190-
bool operator==( const char* other){
190+
bool operator==( const char* other) const {
191191
return strcmp( begin(), other ) == 0 ;
192192
}
193-
bool operator!=( const char* other){
193+
bool operator!=( const char* other) const {
194194
return strcmp( begin(), other ) != 0 ;
195195
}
196196

197-
bool operator==( const string_proxy& other){
197+
template<template <class> class SP>
198+
bool operator==( const string_proxy<STRSXP, SP>& other) const {
198199
return strcmp( begin(), other.begin() ) == 0 ;
199200
}
200-
bool operator!=( const string_proxy& other){
201+
202+
template<template <class> class SP>
203+
bool operator!=( const string_proxy<STRSXP,SP>& other) const {
201204
return strcmp( begin(), other.begin() ) != 0 ;
202205
}
203206

204-
bool operator==( SEXP other ) const {
205-
return get() == other;
206-
}
207-
208-
bool operator!=( SEXP other ) const {
209-
return get() != other;
210-
}
207+
bool operator==( SEXP other ) const {
208+
return get() == other;
209+
}
211210

211+
bool operator!=( SEXP other ) const {
212+
return get() != other;
213+
}
212214

213-
private:
214-
static std::string buffer ;
215+
private:
216+
static std::string buffer ;
215217

216218
} ;
217219

inst/unitTests/cpp/Vector.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,21 @@ List ListNoProtect_crosspolicy(Vector<VECSXP, NoProtectStorage> data){
868868
data2[0] = data[0];
869869
return data2;
870870
}
871+
872+
// [[Rcpp::export]]
873+
bool CharacterVector_test_equality(CharacterVector x, CharacterVector y) {
874+
if (x.length() != y.length()) {
875+
return false;
876+
}
877+
878+
return std::equal(x.begin(), x.end(), y.begin());
879+
}
880+
881+
// [[Rcpp::export]]
882+
bool CharacterVector_test_equality_crosspolicy(CharacterVector x, Vector<STRSXP,NoProtectStorage> y) {
883+
if (x.length() != y.length()) {
884+
return false;
885+
}
886+
887+
return std::equal(x.begin(), x.end(), y.begin());
888+
}

inst/unitTests/runit.Vector.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,4 +772,9 @@ if (.runThisTest) {
772772
data2 <- ListNoProtect_crosspolicy(data)
773773
checkEquals(data, data2)
774774
}
775+
776+
test.CharacterVector_test_equality <- function(){
777+
checkTrue( !CharacterVector_test_equality("foo", "bar") )
778+
checkTrue( !CharacterVector_test_equality_crosspolicy("foo", "bar") )
779+
}
775780
}

0 commit comments

Comments
 (0)