Search code examples
c++templatessfinaeunions

Template specialization for union type


How can I specialise template for union types? Suppose I have template function

template <typename T>
void foo(T value);

I want to prohibit calling this function if T is not any union type. How can I achieve this?


Solution

  • I want to prohibit calling this function if T is not any union type. How can I achieve this?

    Maybe with std::is_union ?

    template <typename T>
    std::enable_if_t<std::is_union<T>::value> foo(T value)
     { /* ... */ }