Title
Missing requirement in constrained function example
Status
concepts
Section
_N2914_.14.11.2 [temp.archetype]
Submitter
Daniel Krügler

Created on 2009-03-01.00:00:00 last changed 187 months ago

Messages

Date: 2009-11-08.00:00:00

The example at the end of _N2914_.14.11.2 [temp.archetype] paragraph 13 reads,

    auto concept CopyConstructible<typename T> {
      T::T(const T&);
    }

    template<CopyConstructible T> struct vector;

    auto concept VectorLike<typename X> {
      typename value_type = typename X::value_type;
      X::X();
      void X::push_back(const value_type&);
      value_type& X::front();
    }

    template<CopyConstructible T>
    requires VectorLike<vector<T>>  // vector<T> is an archetype (but not an instantiated archetype)
    void f(const T& value) {
      vector<T> x;                  // OK: default constructor in VectorLike<vector<T> >
      x.push_back(value);           // OK: push_back in VectorLike<vector<T> >
      VectorLike<vector<T>>::value_type& val = x.front();  // OK: front in VectorLike<vector<T> >
    }

However, x.push_back(value) is, in fact, ill-formed: there is no relationship between VectorLike<vector<T>>::value_type and T in this example. The function needs one further requirement, e.g., std::SameType<VectorLike<vector<T>>::value_type, T> to allow use of the function parameter value as the argument of the push_back call.

History
Date User Action Args
2009-08-03 00:00:00adminsetstatus: drafting -> concepts
2009-03-01 00:00:00admincreate