template c++

#include <iostream>

// Step 1: Declare a template for a generic function that swaps two values of any type
template <typename T>
void swapValues(T& a, T& b) {
    T temp = a;
    a = b;
    b = temp;
}

int main() {
    // Step 2: Declare variables of different types
    int intVar1 = 5, intVar2 = 10;
    double doubleVar1 = 3.14, doubleVar2 = 6.28;

    // Step 3: Display the original values
    std::cout << "Original values:" << std::endl;
    std::cout << "intVar1: " << intVar1 << ", intVar2: " << intVar2 << std::endl;
    std::cout << "doubleVar1: " << doubleVar1 << ", doubleVar2: " << doubleVar2 << std::endl;

    // Step 4: Use the template function to swap values
    swapValues(intVar1, intVar2);
    swapValues(doubleVar1, doubleVar2);

    // Step 5: Display the values after swapping
    std::cout << "\nValues after swapping:" << std::endl;
    std::cout << "intVar1: " << intVar1 << ", intVar2: " << intVar2 << std::endl;
    std::cout << "doubleVar1: " << doubleVar1 << ", doubleVar2: " << doubleVar2 << std::endl;

    return 0;
}