Skip to content

Commit c51a94d

Browse files
committed
Allow per-element comparison of string against non-string iterable (of char).
Test.
1 parent 9a8cdba commit c51a94d

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

include/boost/test/tools/cstring_comparison_op.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <boost/test/tools/assertion.hpp>
1717

1818
#include <boost/test/utils/is_cstring.hpp>
19+
#include <boost/test/utils/is_forward_iterable.hpp>
1920
#include <boost/test/utils/basic_cstring/compare.hpp>
2021

2122
// Boost
@@ -37,8 +38,12 @@ namespace op {
3738
#define DEFINE_CSTRING_COMPARISON( oper, name, rev, name_inverse ) \
3839
template<typename Lhs,typename Rhs> \
3940
struct name<Lhs,Rhs,typename boost::enable_if_c< \
40-
( unit_test::is_cstring_comparable<Lhs>::value \
41-
&& unit_test::is_cstring_comparable<Rhs>::value) \
41+
( ( unit_test::is_cstring_comparable<Lhs>::value \
42+
&& unit_test::is_cstring_comparable<Rhs>::value) \
43+
|| ( unit_test::is_cstring_comparable<Lhs>::value \
44+
&& unit_test::is_forward_iterable<Rhs>::value) \
45+
|| ( unit_test::is_forward_iterable<Lhs>::value \
46+
&& unit_test::is_cstring_comparable<Rhs>::value)) \
4247
>::type > \
4348
{ \
4449
typedef typename unit_test::deduce_cstring_transform<Lhs>::type lhs_char_type; \

test/writing-test-ts/collection-comparison-test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ BOOST_AUTO_TEST_CASE( test_collection_of_collection_comp )
142142

143143
//____________________________________________________________________________//
144144

145+
BOOST_AUTO_TEST_CASE( test_string_non_string_per_element )
146+
{
147+
char const* a = "abc";
148+
std::vector<int> b{'a', 'b', 'c'};
149+
BOOST_TEST( a == b, tt::per_element() );
150+
BOOST_TEST( b == a, tt::per_element() );
151+
}
152+
153+
//____________________________________________________________________________//
154+
145155
// this one does not have const_iterator nor a size, but should be forward iterable
146156
// and possible to use in the collection comparison
147157
struct fwd_iterable_custom {

0 commit comments

Comments
 (0)