typename std::iterator_traits<InIt>::difference_type n,
OutIt d) {
for (; n != 0; --n, ++b, ++d) {
- assert((const void*)&*d != &*b);
*d = *b;
}
return d;
}
private:
- template <class FwdIterator, class P>
+ template <class FwdIterator>
bool replaceAliased(iterator i1, iterator i2,
- FwdIterator s1, FwdIterator s2, P*) {
+ FwdIterator s1, FwdIterator s2, std::false_type) {
return false;
}
template <class FwdIterator>
bool replaceAliased(iterator i1, iterator i2,
- FwdIterator s1, FwdIterator s2, value_type*) {
+ FwdIterator s1, FwdIterator s2, std::true_type) {
static const std::less_equal<const value_type*> le =
std::less_equal<const value_type*>();
const bool aliased = le(&*begin(), &*s1) && le(&*s1, &*end());
return true;
}
-public:
template <class FwdIterator>
void replaceImpl(iterator i1, iterator i2,
FwdIterator s1, FwdIterator s2, std::forward_iterator_tag) {
(void) checker;
// Handle aliased replace
- if (replaceAliased(i1, i2, s1, s2, &*s1)) {
+ if (replaceAliased(i1, i2, s1, s2,
+ std::integral_constant<bool,
+ std::is_same<FwdIterator, iterator>::value ||
+ std::is_same<FwdIterator, const_iterator>::value>())) {
return;
}
ss.str("");
}
+TEST(FBString, rvalueIterators) {
+ // you cannot take &* of a move-iterator, so use that for testing
+ fbstring s = "base";
+ fbstring r = "hello";
+ r.replace(r.begin(), r.end(),
+ make_move_iterator(s.begin()), make_move_iterator(s.end()));
+ EXPECT_EQ("base", r);
+
+ // The following test is probably not required by the standard.
+ // i.e. this could be in the realm of undefined behavior.
+ fbstring b = "123abcXYZ";
+ auto ait = b.begin() + 3;
+ auto Xit = b.begin() + 6;
+ b.replace(ait, b.end(), b.begin(), Xit);
+ EXPECT_EQ("123123abc", b); // if things go wrong, you'd get "123123123"
+}
+
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
google::ParseCommandLineFlags(&argc, &argv, true);