function template
C++
template <class T>
void swap(T & lhs, T & rhs)
{
T tmp = lhs;
lhs = rhs;
rhs = tmp;
}
void main()
{
int a = 6;
int b = 42;
swap<int>(a, b);
printf("a=%d, b=%d\n", a, b);
// Implicit template parameter deduction
double f = 5.5;
double g = 42.0;
swap(f, g);
printf("f=%f, g=%f\n", f, g);
}
/*
Output:
a=42, b=6
f=42.0, g=5.5
*/template <class T>
void swap(T & lhs, T & rhs)
{
T tmp = lhs;
lhs = rhs;
rhs = tmp;
}
Also in C++:
- Title
- bellman ford algorithm cp algorithm
- Category
- C++
- Title
- c++ switch
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- c++ loop through array
- Category
- C++
- Title
- how to get last element of set in c++
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- how to make a heap using stl in c++
- Category
- C++
- Title
- ue4 c++ overlapping functions cpp setup
- Category
- C++
- Title
- c++ overload operator
- Category
- C++
- Title
- hohw toparse a string in c++
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- c++ loop through int array
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- how can make string value in cpp
- Category
- C++
- Title
- how do for loops on c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- c++ char print align
- Category
- C++
- Title
- how to convert string into number
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- Given an undirected graph, count the number of connected components.
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- cin.fail()
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- c++ compiler for sublime text
- Category
- C++
- Title
- do while loop c++
- Category
- C++
- Title
- restting a queue stl
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- c++ class constructor
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- c++ menu selection with arrow keys
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- c++ pi
- Category
- C++
- Title
- regexp_like oracle c++
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorBad memory access (SIGBUS)
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- random number in c++
- Category
- C++
- Title
- constant variables in c++
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- c++ initialize array
- Category
- C++
- Title
- input a string in c++
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- timer in c++
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- std::substring
- Category
- C++
- Title
- dfs in c++
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- while loops
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++
- Title
- access last element in vector in c++
- Category
- C++
- Title
- how to use winmain function
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- kruskal c++
- Category
- C++
- Title
- append string to another string c++
- Category
- C++
- Title
- qt graphics scene map cursor position
- Category
- C++
- Title
- howt o initialize 3d vector in c++
- Category
- C++
- Title
- find_if c++ example
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- c++ vector add element
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- uepic games github
- Category
- C++
- Title
- All palindromic substrings
- Category
- C++
- Title
- add a timer c++
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- c++ char if
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- vertical traversal of binary tree
- Category
- C++
- Title
- what does the modularity mean in c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- mao two drivers c++
- Category
- C++
- Title
- how to take input in C++ in coding
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- c++ how to make a negative float positive
- Category
- C++
- Title
- mkdir c++
- Category
- C++
- Title
- pairs in c++
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- c++ file to string
- Category
- C++
- Title
- c++ multidimensional vector
- Category
- C++
- Title
- factorion
- Category
- C++
- Title
- what is atoi in strinf
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- c++ iterate through constant list
- Category
- C++