On 16 Mar 2007 20:52:10 -0700,
n.************@gmail.com wrote:
>std::pair explicitly defines a default constructor. This makes it
impossible to instantiate it with a type that does not have a default
constructor (or it is private).
I wonder if it would be possible to define std::pair in such a way
(using template metaprogramming) that the default constructor is
defined if and only if both of pair's argument types are default-
constructible.
You don't need template metaprogramming for that--you just need to remove the
default constructor from the class definition. Of course then you'll end up
with something /other/ than std::pair.
There are many reasons to give "value-like" classes default constructors. One
of which is that you can then have a vector or array of it without explicitly
contsructing each member. In other words, std::vector<std::pair<Type1, Type2>
wouldn't be possible if std::pair didn't have a default contsructor.
-dr