Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restricting function template types in Visual Studio 2012

Is there any way in Visual Studio 2012 to restrict function templates to specific types?

This one works in GCC, but MSVC generates error C4519: default template arguments are only allowed on a class template.

#include <type_traits>

template <class float_t, class = typename std::enable_if< std::is_floating_point<float_t>::value >::type>
inline float_t floor(float_t x)
{
    float_t result;
    //...
    return result;
}

A cross compiler solution would be the best. Any alternative?

like image 423
plasmacel Avatar asked May 06 '26 12:05

plasmacel


1 Answers

Normally, you would write this as

template <class float_t>
typename std::enable_if< std::is_floating_point<float_t>::value, float_t>::type
  floor(float_x x) {...}

That's how enable_if is intended to be used.

like image 172
Igor Tandetnik Avatar answered May 08 '26 02:05

Igor Tandetnik