From d0f3f64bb42ea8194c20f0eadd35821cab346143 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 17 Jan 2025 07:52:02 +0100 Subject: Started work on templates article --- templates/swap.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 templates/swap.cpp (limited to 'templates/swap.cpp') 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 @@ +#include + +template +void swap(S& a, T& b) { + S tmp = a; + a = b; + b = tmp; +} + +int main() { + int x = 3; + std::string y = "1.0"; + swap(x, y); + std::cout << "x: " << x << std::endl; + std::cout << "y: " << y << std::endl; +} -- cgit v1.3