#11625 closed Bugs (invalid)
BOOST_TEST( ..., per_element() ) erroneously requires collections are comparable
Reported by: | Owned by: | Raffi Enficiaud | |
---|---|---|---|
Milestone: | To Be Determined | Component: | test |
Version: | Boost 1.60.0 | Severity: | Problem |
Keywords: | BOOST_TEST, per_element, collections, comparable, element, range, equality | Cc: |
Description
Thanks for the new BOOST_TEST() and per_element() tools, which look very useful.
Unfortunately, I'm having trouble with comparing collections that aren't themselves comparable but have comparable elements.
As I understand the requirements documentation for the BOOST_TEST / per_element() tools, they should only require that the two collections' elements are comparable, not necessarily the two collections themselves. I think this approach makes a lot of sense.
However, when I try to compile the following under either g++ -std=c++11
or clang -std=c++11 -stdlib=libc++
, the compilers complain that collections aren't comparable :
#define BOOST_TEST_MODULE comp_by_elem_mod #include <boost/test/included/unit_test.hpp> #include <iterator> #include <vector> struct my_class final { std::vector<int> the_ints = { 1, 2, 3 }; using const_iterator = std::vector<int>::const_iterator; const_iterator begin() const { return std::begin( the_ints ); } const_iterator end() const { return std::end( the_ints ); } }; BOOST_AUTO_TEST_CASE( comp_by_elem ) { const my_class a{}; const std::vector<int> b = { 1, 2, 3 }; BOOST_TEST( a == b, ::boost::test_tools::per_element() ); }
I'll attach compiler errors.
Many thanks.
Attachments (2)
Change History (13)
by , 7 years ago
Attachment: | clang_compiler_errors.err added |
---|
comment:1 by , 7 years ago
Component: | None → test |
---|---|
Owner: | set to |
comment:2 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Fixed in develop, assigning to keep track.
comment:3 by , 7 years ago
Version: | Boost 1.57.0 → Boost 1.59.0 |
---|
comment:4 by , 7 years ago
Milestone: | To Be Determined → Boost 1.60.0 |
---|
comment:6 by , 7 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Version: | Boost 1.59.0 → Boost 1.60.0 |
I'm still seeing this problem in Boost 1.60.0. Is that expected?
comment:7 by , 7 years ago
Hi,
I just tried your example, and I can reproduce the problem. This is because your class my_class_final
does not follow the requirements for the sequence as defined here.
After adding members size
and value_type
it works as expected. Would you please confirm?
comment:8 by , 7 years ago
Milestone: | Boost 1.60.0 → To Be Determined |
---|
comment:9 by , 7 years ago
Thanks for this, yes I can confirm that I'm able to fix my problems by adding size
and value_type
. Sorry - I should have RTFM properly :-).
To make it harder for others to repeat my mistake, it might be useful to:
- add a note here to explicitly state that the comparators must meet the requirements of a sequence and then link to the definition further down that page that you highlighted.
- ideally use a
Sequence
concept to make the compiler errors more helpful. I realise that you may be keen to avoid adding a dependency to the Boost Concept library.
Again, thanks and apologies. I'm happy for you to close this ticket.
comment:10 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
I added an entry to the doc as you suggested (rev 1976cc2). We are not too keen in adding dependencies though.
Thanks, Raffi
clang