Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11625 closed Bugs (invalid)

BOOST_TEST( ..., per_element() ) erroneously requires collections are comparable

Reported by: Tony Lewis <tonyelewis@…> 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)

clang_compiler_errors.err (3.4 KB ) - added by Tony Lewis <tonyelewis@…> 7 years ago.
clang
gcc_compiler_errors.err (103.6 KB ) - added by Tony Lewis <tonyelewis@…> 7 years ago.
g++ compilation errors

Download all attachments as: .zip

Change History (13)

by Tony Lewis <tonyelewis@…>, 7 years ago

Attachment: clang_compiler_errors.err added

clang

by Tony Lewis <tonyelewis@…>, 7 years ago

Attachment: gcc_compiler_errors.err added

g++ compilation errors

comment:1 by Tony Lewis <tonyelewis@…>, 7 years ago

Component: Nonetest
Owner: set to Gennadiy Rozental

comment:2 by Raffi Enficiaud, 7 years ago

Owner: changed from Gennadiy Rozental to Raffi Enficiaud
Status: newassigned

Fixed in develop, assigning to keep track.

comment:3 by Raffi Enficiaud, 7 years ago

Version: Boost 1.57.0Boost 1.59.0

comment:4 by Raffi Enficiaud, 7 years ago

Milestone: To Be DeterminedBoost 1.60.0

comment:5 by Raffi Enficiaud, 7 years ago

Resolution: fixed
Status: assignedclosed

merged to master

comment:6 by Tony Lewis <tonyelewis@…>, 7 years ago

Resolution: fixed
Status: closedreopened
Version: Boost 1.59.0Boost 1.60.0

I'm still seeing this problem in Boost 1.60.0. Is that expected?

comment:7 by Raffi Enficiaud, 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 Raffi Enficiaud, 7 years ago

Milestone: Boost 1.60.0To Be Determined

comment:9 by Tony Lewis <tonyelewis@…>, 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 Raffi Enficiaud, 7 years ago

Resolution: invalid
Status: reopenedclosed

I added an entry to the doc as you suggested (rev 1976cc2). We are not too keen in adding dependencies though.

Thanks, Raffi

comment:11 by Tony Lewis <tonyelewis@…>, 7 years ago

Great, thanks.

Note: See TracTickets for help on using tickets.