Skip to content

Commit 9c8562a

Browse files
more generic StringProxy::operator== so that it works cross policies.
1 parent b01a1bd commit 9c8562a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

inst/include/Rcpp/vector/string_proxy.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,13 @@ namespace internal{
194194
return strcmp( begin(), other ) != 0 ;
195195
}
196196

197-
bool operator==( const string_proxy& other) const {
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) const {
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

inst/unitTests/cpp/Vector.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,12 @@ bool CharacterVector_test_equality(CharacterVector x, CharacterVector y) {
877877

878878
return std::equal(x.begin(), x.end(), y.begin());
879879
}
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ if (.runThisTest) {
774774
}
775775

776776
test.CharacterVector_test_equality <- function(){
777-
checkTrue( !CharacterVector_test_equality("foo", "bar") )
777+
checkTrue( !CharacterVector_test_equality("foo", "bar") )
778+
checkTrue( !CharacterVector_test_equality_crosspolicy("foo", "bar") )
778779
}
779780
}

0 commit comments

Comments
 (0)