Title
Container adaptor swap: member or non-member?
Status
c++11
Section
[container.adaptors]
Submitter
Pablo Halpern

Created on 2009-08-26.00:00:00 last changed 154 months ago

Messages

Date: 2010-11-24.14:01:03

Proposed resolution:

Change [queue.defn]:

template <class T, class Container = deque<T> > 
class queue {
   ...
   void swap(queue& q) { using std::swap;
                          c.swap(c, q.c); }
   ...
};

Change [priority.queue]:

template <class T, class Container = vector<T>, 
          class Compare = less<typename Container::value_type> > 
class priority_queue { 
    ...
    void swap(priority_queue& q); { using std::swap;
                                     swap(c, q.c);
                                     swap(comp, q.comp); }
    ...
};

Change [stack.defn]:

template <class T, class Container = deque<T> > 
class stack {
   ...
   void swap(stack& s) { using std::swap;
                          c.swap(c, s.c); }
   ...
};
Date: 2010-11-24.14:01:03

[ Adopted at 2010-11 Batavia ]

Date: 2010-10-21.19:00:35

[ 2010 Rapperswil: ]

Preference to move the wording into normative text, rather than inline function definitions in the class synopsis. Move to Tenatively Ready.

Date: 2010-03-28.00:00:00

[ 2010-03-28 Daniel update to diff against N3092. ]

Date: 2009-09-30.00:00:00

[ 2009-09-30 Daniel adds: ]

The outcome of this issue should be considered with the outcome of 774 both in style and in content (e.g. 774 bullet 9 suggests to define the semantic of void priority_queue::swap(priority_queue&) in terms of the member swap of the container).

Date: 2009-08-26.00:00:00

Under [container.adaptors] of N2914 the member function of swap of queue and stack call:

swap(c, q.c);

But under [container.adaptors] of N2723 these members are specified to call:

c.swap(q.c);

Neither draft specifies the semantics of member swap for priority_queue though it is declared.

Although the distinction between member swap and non-member swap is not important when these adaptors are adapting standard containers, it may be important for user-defined containers.

We (Pablo and Howard) feel that it is more likely for a user-defined container to support a namespace scope swap than a member swap, and therefore these adaptors should use the container's namespace scope swap.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-11-24 14:01:03adminsetmessages: + msg5419
2010-11-14 13:10:57adminsetstatus: voting -> wp
2010-11-08 14:14:39adminsetstatus: ready -> voting
2010-10-21 19:00:35adminsetmessages: + msg4753
2010-10-21 19:00:35adminsetstatus: new -> ready
2010-10-21 18:28:33adminsetmessages: + msg1114
2010-10-21 18:28:33adminsetmessages: + msg1113
2010-10-21 18:28:33adminsetmessages: + msg1112
2009-08-26 00:00:00admincreate