diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-01-17 07:52:02 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-01-17 07:52:02 +0100 |
| commit | d0f3f64bb42ea8194c20f0eadd35821cab346143 (patch) | |
| tree | 84355ea4008769382a8300aa11b2b43fd9dd86c1 /templates/swap.cpp | |
| parent | 873ae98050baf54a9a17ac54896de732134206af (diff) | |
| download | taming-cpp-d0f3f64bb42ea8194c20f0eadd35821cab346143.tar.gz taming-cpp-d0f3f64bb42ea8194c20f0eadd35821cab346143.zip | |
Started work on templates article
Diffstat (limited to '')
| -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 | } | ||
