diff options
Diffstat (limited to 'templates/swap.cpp')
| -rw-r--r-- | templates/swap.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/templates/swap.cpp b/templates/swap.cpp new file mode 100644 index 0000000..94e231e --- /dev/null +++ b/templates/swap.cpp | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include <iostream> | ||
| 2 | |||
| 3 | template<typename S, typename T> | ||
| 4 | void swap(S& a, T& b) { | ||
| 5 | S tmp = a; | ||
| 6 | a = b; | ||
| 7 | b = tmp; | ||
| 8 | } | ||
| 9 | |||
| 10 | int main() { | ||
| 11 | int x = 3; | ||
| 12 | std::string y = "1.0"; | ||
| 13 | swap(x, y); | ||
| 14 | std::cout << "x: " << x << std::endl; | ||
| 15 | std::cout << "y: " << y << std::endl; | ||
| 16 | } | ||
