dimanche 28 décembre 2014

std::enable_if and template alias, prevent user from filling in std::enable_if parameter

I'm using template aliases like so:



template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
using vec2 = std::pair<T, T>;

template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
using vec3 = std::tuple<T, T, T>;


The problem is anyone can subvert this by doing vec2<int, any_type>. How do I prevent this?


Aucun commentaire:

Enregistrer un commentaire