c 2b 2b template specialization

Solutions on MaxInterview for c 2b 2b template specialization by the best coders in the world

showing results for - "c 2b 2b template specialization"
Chenai
28 Jul 2017
1#include <iostream>
2template<typename T>   // primary template
3struct is_void : std::false_type
4{
5};
6template<>  // explicit specialization for T = void
7struct is_void<void> : std::true_type
8{
9};
10int main()
11{
12    // for any type T other than void, the 
13    // class is derived from false_type
14    std::cout << is_void<char>::value << '\n'; 
15    // but when T is void, the class is derived
16    // from true_type
17    std::cout << is_void<void>::value << '\n';
18}