std::pair
missing template assignmentSection: 22.3 [pairs] Status: Resolved Submitter: Martin Sebor Opened: 2001-12-02 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [pairs].
View all issues with Resolved status.
Discussion:
The class template std::pair
defines a template ctor (20.2.2, p4) but
no template assignment operator. This may lead to inefficient code since
assigning an object of pair<C, D>
to pair<A, B>
where the types C
and D
are distinct from but convertible to
A
and B
, respectively, results in a call to the template copy
ctor to construct an unnamed temporary of type pair<A, B>
followed by an ordinary (perhaps implicitly defined) assignment operator,
instead of just a straight assignment.
Proposed resolution:
Add the following declaration to the definition of std::pair
:
template<class U, class V> pair& operator=(const pair<U, V> &p);
And also add a paragraph describing the effects of the function template to the end of 20.2.2:
template<class U, class V> pair& operator=(const pair<U, V> &p);
Effects: first = p.first;
second = p.second;
Returns: *this
[Curaçao: There is no indication this is was anything other than a design decision, and thus NAD. May be appropriate for a future standard.]
[
Pre Bellevue: It was recognized that this was taken care of by
N1856,
and thus moved from NAD Future to NAD EditorialResolved.
]