Title
make_pair() unintended behavior
Status
tc1
Section
[pairs]
Submitter
Andrew Koenig

Created on 1999-08-03.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

Two potential fixes were suggested by Matt Austern and Dietmar Kühl, respectively, 1) overloading with array arguments, and 2) use of a reference_traits class with a specialization for arrays. Andy Koenig suggested changing to pass by value. In discussion, it appeared that this was a much smaller change to the standard that the other two suggestions, and any efficiency concerns were more than offset by the advantages of the solution. Two implementors reported that the proposed resolution passed their test suites.

Date: 2010-10-21.18:28:33

Proposed resolution:

In [utility], paragraph 1 change the following declaration of make_pair():

template <class T1, class T2> pair<T1,T2> make_pair(const T1&, const T2&);

to:

template <class T1, class T2> pair<T1,T2> make_pair(T1, T2);

In [pairs] paragraph 7 and the line before, change:

template <class T1, class T2>
pair<T1, T2> make_pair(const T1& x, const T2& y);

to:

template <class T1, class T2>
pair<T1, T2> make_pair(T1 x, T2 y);

and add the following footnote to the effects clause:

According to 12.8 [class.copy], an implementation is permitted to not perform a copy of an argument, thus avoiding unnecessary copies.

Date: 1999-08-03.00:00:00

The claim has surfaced in Usenet that expressions such as

       make_pair("abc", 3)

are illegal, notwithstanding their use in examples, because template instantiation tries to bind the first template parameter to const char (&)[4], which type is uncopyable.

I doubt anyone intended that behavior...

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1773
2010-10-21 18:28:33adminsetmessages: + msg1772
1999-08-03 00:00:00admincreate