Custom swap in std namespace

  • Thread starter Marcin Kalicinski
  • Start date
M

Marcin Kalicinski

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

cheers,
Marcin
 
V

Victor Bazarov

Marcin said:
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
 
R

red floyd

Victor said:
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&);
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top