c++ - How to combine boost::range with BOOST_<level>_EQUAL_COLLECTION? -
is possible combine boost__equal_collection boost::range such can simplify:
#include <boost/test/unit_test.hpp> std::vector<int> mysort(std::vector<int>); ... auto lhs = mysort({ 11, 7, 5, 3, 2 }); const std::vector<int> rhs = { 2, 3, 5, 7, 11 }; boost_check_equal_collections(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
to like
boost_check_equal_collections(mysort({ 11, 7, 5, 3, 2 }), { 2, 3, 5, 7, 11 });
apart being less verbose, see additional benefit of more useful warning, reads:
error in "foo": check { lhs.begin(), lhs.end() } == { rhs.begin(), rhs.end() } failed.
which not useful.
i'm afraid boost::range
won't here. problem how boost_check_equal_collections
defined.
you can define macro yourself:
#define collections_check_equal(a, b) boost_check_equal_collections(std::begin(a), std::end(a), std::begin(b), std::end(b))
and use as:
collections_check_equal(mysort(std::vector<int>{ 11, 7, 5, 3, 2 }), std::vector<int>{ 2, 3, 5, 7, 11 });
Comments
Post a Comment