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: 23.6 [container.adaptors] Status: C++11 Submitter: Pablo Halpern Opened: 2009-08-26 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [container.adaptors].

View all issues with C++11 status.

Discussion:

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

swap(c, q.c);

But under 23.6 [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.

[ 2009-09-30 Daniel adds: ]

The outcome of this issue should be considered with the outcome of 774(i) both in style and in content (e.g. 774(i) 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 23.6.3.1 [queue.defn]:

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

Change 23.6.4 [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 23.6.6.2 [stack.defn]:

template <class T, class Container = deque<T> > 
class stack {
   ...
   void swap(stack& s) { using std::swap;
                          c.swap(c, s.c); }
   ...
};
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy