What does "typename Enable = void" mean?

I found that typename Enable = void is defined in ProtoBuf ,

 template<typename T, typename Enable = void> struct RefTypeTraits; 

However, I cannot find that Enable used in this header file , which bothers me. What does typename Enable = void mean in a template?

+5
source share
2 answers

There are only two template options in your template. The second is called "Enabled" and is of the default "void" type. This is a trick to allow SFINAE later.

+3
source

This means that SFINAE has a specialized specialization, something like

 template<typename T> struct RefTypeTraits<T, std::enable_if_t<some_condition<T>::value>> { // ... specialization for T which respects condition }; 
+3
source

Source: https://habr.com/ru/post/1239180/


All Articles