[ConceptGCC] |
ConceptGCC :Is this well-formed? -- ConceptGCC doesn't like it. |
From: Sebastian Gesemann (s.gesemann_at_[hidden])
Date: 2008-12-08 14:10:38
Hi!
I noticed that the following code doesn't behave like originally intended:
template<typename T>
class Clazz {
public:
requires std::CopyConstructible<T>
void push_back(T const&);
requires std::MoveConstructible<T>
void push_back(T &&);
};
The second function push_back(T&&) is always selected for non-copyable
types (even for Lvalues!) because the CopyConstructible requires
clause prevents the first function from participating in overload
resolution. This piece of code is just a simplification of what you
can find in the current standard draft (N2798.pdf, 23.2.6, page 826,
[vector]).
To fix this I came up with:
template<typename T>
class Clazz {
public:
requires !std::CopyConstructible<T> // note the "!"
void push_back(T const&); // = delete
requires std::CopyConstructible<T>
void push_back(T const&); // use copy-construct
requires std::MoveConstructible<T>
void push_back(T &&); // use move-construct
};
The motivation was to always make a push_back function taking an
lvalue reference part of the overload resolution set. But this won't
compile using ConceptGCC (subversion revision 727). I wonder whether
it is even well-formed with respect to the current draft. The error
message (translated from German) is:
vectest.cpp:41: Error: »void Clazz<T>::push_back(const T&)«
can't be overloaded with
vectest.cpp:36: Error: »void Clazz<T>::push_back(const T&)«
Cheers!
SG