首页 > 解决方案 > 使用 SFINAE 重载模板变量特化

问题描述

以下代码:

template<class S, class = void>
constexpr bool is_size = false;
template<class S>
constexpr bool is_size<S, std::void_t<decltype(S::cx, S::cy)>> = true;
template<class S>
constexpr bool is_size<S, std::void_t<decltype(S::width, S::height)>> = true;

error : redefinition of 'is_size<S, std::void_t<decltype(S::width , S::height)>>'.

是否有可能以某种方式实现这个想法,或者唯一可以做的就是与所有尺寸类型进行比较?

标签: c++templatessfinaetemplate-variables

解决方案


推荐阅读