473,320 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Custom swap in std namespace

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

cheers,
Marcin
Dec 5 '05 #1
2 1698
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
Dec 5 '05 #2
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&);
}

Dec 5 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
by: Steve | last post by:
How do you rewrite the swap function without using a tmp variable in the swap function???? int main() { int x = 3; int y = 5; // Passing by reference
2
by: ma740988 | last post by:
So I'm reading the C++ coding standards(Shutter & Andrei), more specifically item 56. There's a statement: "Prefer to provide a nonmember swap function in the same namespace as your type when...
7
by: Kai-Uwe Bux | last post by:
Hi folks, I am still struggling with the rules for name lookup. Please consider: namespace xxx {
9
by: Jongmin Lee | last post by:
Hi Everybody, I have very simple code snippet to explain my problem. Class "Swap" is construncted in "Main" with two initial variables. Later, "Swap" class is going to swap those two...
1
by: Sung Jin Hwang | last post by:
Hi. Is there a good way to extend std::swap to user type classes? Overloading can be a solution but when user type is not a class but class template, we need partial specialization and function...
4
by: Niels Dekker (no reply address) | last post by:
When calling swap as follows (as recommanded in Effective C++, 3rd Edition, by Scott Meyers), what swap is chosen to be called? using std::swap; swap(a, b); Suppose there is a global ::swap...
3
by: Narmada Padhy | last post by:
1> #include<iostream> using namespace std; void swap(int& i, int& j) { int tmp = i; i = j; j = tmp; cout<<"The value after swap of x and y is"<<i<<" "<<j<<endl;
4
by: DanielGifford | last post by:
Hi I'm making some basic cryptography software and I've run into a snag. I'm trying to retrieve some sort of system number thats specific to the system I'm working on. It can't change over...
21
by: raylopez99 | last post by:
In the otherwise excellent book C# 3.0 in a Nutshell by Albahari et al. (3rd edition) (highly recommended--it's packed with information, and is a desktop reference book) the following statement is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.