Is it possible to deduce the type of a non-standard template in C ++ 11?

C ++ 17 has this nice feature that allows you to declare arguments to a non-type template with the auto keyword:

 template<auto a> void foo(); 

which allows you to display this type of parameter, for example:

 foo<3>() <-- a has deduced type of 'int' 

Unfortunately, I have to use a compiler that does not support C ++ 17 and does not fully support C ++ 11 (it lacks support for the standard library). So my question is: is it possible to achieve the same effect using C ++ 11?

The only way I could come up with is to use a macro:

 template< typename T, T a> void foo(); #define CALL_FOO( x ) foo< decltype(x), x >() 
+5
source share

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


All Articles