Answers for "c++ template specialization"

C++
0

c++ template specialization

#include <iostream>
template<typename T>   // primary template
struct is_void : std::false_type
{
};
template<>  // explicit specialization for T = void
struct is_void<void> : std::true_type
{
};
int main()
{
    // for any type T other than void, the 
    // class is derived from false_type
    std::cout << is_void<char>::value << '\n'; 
    // but when T is void, the class is derived
    // from true_type
    std::cout << is_void<void>::value << '\n';
}
Posted by: Guest on July-24-2021

Code answers related to "c++ template specialization"

Browse Popular Code Answers by Language