Skip to content

Commit

Permalink
Allow per-element comparison of string against non-string iterable (o…
Browse files Browse the repository at this point in the history
…f char).

Test.
  • Loading branch information
ecatmur committed Apr 12, 2020
1 parent 9a8cdba commit c51a94d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions include/boost/test/tools/cstring_comparison_op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <boost/test/tools/assertion.hpp>

#include <boost/test/utils/is_cstring.hpp>
#include <boost/test/utils/is_forward_iterable.hpp>
#include <boost/test/utils/basic_cstring/compare.hpp>

// Boost
Expand All @@ -37,8 +38,12 @@ namespace op {
#define DEFINE_CSTRING_COMPARISON( oper, name, rev, name_inverse ) \
template<typename Lhs,typename Rhs> \
struct name<Lhs,Rhs,typename boost::enable_if_c< \
( unit_test::is_cstring_comparable<Lhs>::value \
&& unit_test::is_cstring_comparable<Rhs>::value) \
( ( unit_test::is_cstring_comparable<Lhs>::value \
&& unit_test::is_cstring_comparable<Rhs>::value) \
|| ( unit_test::is_cstring_comparable<Lhs>::value \
&& unit_test::is_forward_iterable<Rhs>::value) \
|| ( unit_test::is_forward_iterable<Lhs>::value \
&& unit_test::is_cstring_comparable<Rhs>::value)) \
>::type > \
{ \
typedef typename unit_test::deduce_cstring_transform<Lhs>::type lhs_char_type; \
Expand Down
10 changes: 10 additions & 0 deletions test/writing-test-ts/collection-comparison-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ BOOST_AUTO_TEST_CASE( test_collection_of_collection_comp )

//____________________________________________________________________________//

BOOST_AUTO_TEST_CASE( test_string_non_string_per_element )
{
char const* a = "abc";
std::vector<int> b{'a', 'b', 'c'};
BOOST_TEST( a == b, tt::per_element() );
BOOST_TEST( b == a, tt::per_element() );
}

//____________________________________________________________________________//

// this one does not have const_iterator nor a size, but should be forward iterable
// and possible to use in the collection comparison
struct fwd_iterable_custom {
Expand Down

0 comments on commit c51a94d

Please sign in to comment.