1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <boost/utility/enable_if.hpp>
struct Color
{
template<class T>
Color( T const& r, T const& g, T const& b, T const& alpha = T(255), typename boost::enable_if< boost::is_integral<T> >::type* = 0 )
{ std::cout << "char\n"; }
template<class T1,class T2,class T3,class T4>
Color( T1 const& r, T2 const& g, T3 const& b, T4 const& alpha = T4(1.f)
, typename boost::
enable_if_c< boost::is_floating_point<T1>::value
|| boost::is_floating_point<T2>::value
|| boost::is_floating_point<T3>::value
|| boost::is_floating_point<T4>::value
>::type* = 0 )
{ std::cout << "float\n"; }
};
int main()
{
Color c(1,2,3,4);
Color f(1.f,2.f,3.f,0.f);
Color fc(1.f,2,3.f,0.f);
Color cf(1,2,3,0.f);
} |
Partager