This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

1198. Container adaptor swap: member or non-member?

Section: 21.6 [container.adaptors] Status: C++11 Submitter: Pablo Halpern Opened: 2009-08-26 Last modified: 2017-02-03

Priority: Not Prioritized

View all other issues in [container.adaptors].

View all issues with C++11 status.


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

swap(c, q.c);

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


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.

[ 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).

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

[ 2010 Rapperswil: ]

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

[ Adopted at 2010-11 Batavia ]

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 21.6.5 [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); }