This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: operator== missing on std::__debug::map<>::iterator

2012/12/11 Gabriel Dos Reis <>:
> On Mon, Dec 10, 2012 at 3:42 PM, Daniel Krügler
> <> wrote:
>> 2012/12/10 Jonathan Wakely <>
>>> On 10 December 2012 21:29, Marc Glisse wrote:
>>> >
>>> > By the way, would the standard allow those iterators to be final? (not
>>> > suggesting it, just asking, because it doesn't seem forbidden)
>>> I have a vague recollection of discussing this in the past somewhere
>>> and the consensus was that implementations cannot add 'final' to such
>>> types.  But I might be misremembering the discussion.
>> I think that implementation-provided iterator belong to the "gray zone" where
>> declaring them as final would be feasible, see
>> - Daniel
> Why should a C++ program care about iterator being final or not?
> (I am not talking about conformance testsuites.)

I have seen such code and written it ;-): If you have to manage a set
of compilers
where at least one has very little sfinae support, a typical way to
check whether
a template argument type satisfies some constraints (such is: "is it
an input iterator?"
or "is it callable with a specific set of arguments") involves a
sub-branch (after having
eliminated non-class types) that ad-hoc derives from the template argument type.
Here a code snippet of this quite popular technique:

struct testers
  struct Fallback
    void operator++();
    void operator*();

  template<class U>
  static two test1(type_value<void (Fallback::*)(), &U::operator++>*);

  static one test1(...);

  template<class U>
  static two test2(type_value<void (Fallback::*)(), &U::operator*>*);

  static one test2(...);

template<class T, bool = ::boost::is_class<T>::value>
struct has : testers
  struct Derived : T, Fallback {};

  static const bool value = sizeof(test1<Derived>(0)) == sizeof(one) &&
                            sizeof(test2<Derived>(0)) == sizeof(one);
  typedef has type;

The technique is a C++03 technique but you cannot replace all your previously
valid code when you switch to a C++11 environment.

- Daniel

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]