Boost logo

Boost :

Subject: Re: [boost] [type_traits] has_equal_to< std::vector<T> > always true_
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2012-07-07 01:34:04

Hi Lorenzo,

Thanks for pushing this topic. Sorry to only replying now but it is
hard to find some free time with 3 little children!

I have looked a bit at the standard (ISO/IEC 14882, 2011). The
relevant text is: 23.2.1, Table 96, 25.2.11.

This is what I have found:

if a and b are container<T> and t1 and t2 are T:
- a==b: requires t1==t2 returning convertible to bool
- a!=b: requires a==b
- a<b: calls std::lexicographical_compare -> requires t1<t2 returning
convertible to bool
  . a>b: requires b<a
  . a<=b: requires !(b<a)
  . a>=b: requires !(a<b)

So in short: a==b and a!=b require t1==t2 and a<b, a>b, a<=b, a>=b
require t1<t2 returning convertible to bool.

> namespace std { // fwd decl so no need to include STL
> template< typename T, class Alloc > class vector;
> } // namespace std

Concerning your proposal to forward declare the containers, it is
halas not allowed by the standard ( Namespace std):
"The behavior of a C++ program is undefined if it adds declarations or
definitions to namespace std or to a namespace within namespace std
unless otherwise specified."

I imagine easily that it should behave as intended but it seems
possible for an implementation to not like it.

> template< typename T, class LhsAlloc, class RhsAlloc, typename Ret >
> struct has_equal_to < std::vector<T, LhsAlloc >, std::vector<T, RhsAlloc >, Ret > : has_equal_to<T, T, Ret>
> {};

The standard defines the operators only for identical allocators.
operator== always returns bool and has_equal_to should return
convertible to bool. This should be reflected in the declaration.


Boost list run by bdawes at, gregod at, cpdaniel at, john at