Custom swap in std namespace

Discussion in 'C++' started by Marcin Kalicinski, Dec 5, 2005.

  1. Is it well formed C++ to define free swap function for my custom container
    in std namespace?

    cheers,
    Marcin
     
    Marcin Kalicinski, Dec 5, 2005
    #1
    1. Advertisements

  2. Marcin Kalicinski wrote:
    > Is it well formed C++ to define free swap function for my custom container
    > in std namespace?


    Yes. You are allowed to _specialise_ any of 'std' templates for your
    particular types.

    V
     
    Victor Bazarov, Dec 5, 2005
    #2
    1. Advertisements

  3. Marcin Kalicinski

    red floyd Guest

    Victor Bazarov wrote:
    > Marcin Kalicinski wrote:
    >
    >> Is it well formed C++ to define free swap function for my custom
    >> container in std namespace?

    >
    >
    > Yes. You are allowed to _specialise_ any of 'std' templates for your
    > particular types.
    >
    > V


    So, the first of the following two functions is OK, but not the second,
    since the second is an overload and not a specialization?

    class MyClass;

    namespace std {
    template<>
    void swap<MyClass>(MyClass&, MyClass&);
    }

    namespace std {
    void swap(MyClass&, MyClass&);
    }
     
    red floyd, Dec 5, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Petter Reinholdtsen
    Replies:
    9
    Views:
    4,793
    Howard
    Nov 29, 2004
  2. Peter Jansson
    Replies:
    5
    Views:
    6,985
    Ivan Vecerina
    Mar 17, 2005
  3. Vinu
    Replies:
    4
    Views:
    543
    Jim Langston
    Jul 7, 2005
  4. Jason Heyes
    Replies:
    8
    Views:
    1,018
    Andrew Koenig
    Jan 15, 2006
  5. Niels Dekker (no reply address)

    What swap is called when using std::swap?

    Niels Dekker (no reply address), Jul 19, 2006, in forum: C++
    Replies:
    4
    Views:
    1,247
    Niels Dekker (no reply address)
    Jul 20, 2006
  6. Replies:
    7
    Views:
    630
    Jacek Dziedzic
    Oct 3, 2006
  7. bb
    Replies:
    1
    Views:
    416
    Alf P. Steinbach
    Sep 7, 2007
  8. Shriramana Sharma
    Replies:
    2
    Views:
    262
    Shriramana Sharma
    Jun 27, 2013
Loading...