Skip to content

Commit b01a1bd

Browse files
make StringProxy::operator== const to lift ambiguities. closes #854
1 parent 8c360a8 commit b01a1bd

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

inst/include/Rcpp/vector/string_proxy.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,31 +187,30 @@ 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+
bool operator==( const string_proxy& other) const {
198198
return strcmp( begin(), other.begin() ) == 0 ;
199199
}
200-
bool operator!=( const string_proxy& other){
200+
bool operator!=( const string_proxy& other) const {
201201
return strcmp( begin(), other.begin() ) != 0 ;
202202
}
203203

204-
bool operator==( SEXP other ) const {
205-
return get() == other;
206-
}
204+
bool operator==( SEXP other ) const {
205+
return get() == other;
206+
}
207207

208-
bool operator!=( SEXP other ) const {
209-
return get() != other;
210-
}
208+
bool operator!=( SEXP other ) const {
209+
return get() != other;
210+
}
211211

212-
213-
private:
214-
static std::string buffer ;
212+
private:
213+
static std::string buffer ;
215214

216215
} ;
217216

inst/unitTests/cpp/Vector.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,12 @@ 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+
}

inst/unitTests/runit.Vector.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,4 +772,8 @@ 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+
}
775779
}

0 commit comments

Comments
 (0)