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. Advertising

  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. Advertising

  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. Advertising

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,344
    Howard
    Nov 29, 2004
  2. Jason Heyes
    Replies:
    8
    Views:
    712
    Andrew Koenig
    Jan 15, 2006
  3. 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:
    976
    Niels Dekker (no reply address)
    Jul 20, 2006
  4. Replies:
    7
    Views:
    417
    Jacek Dziedzic
    Oct 3, 2006
  5. bb
    Replies:
    1
    Views:
    295
    Alf P. Steinbach
    Sep 7, 2007
Loading...

Share This Page