The following function is defined for all arithmetic types:
template <class T>
typename enable_if_c<boost::is_arithmetic<T>::value, T>::type
foo(T t) { return t; }
Question 1> what does the value mean here? Why not simply use boost::is_arithmetic<T>?
boost::is_arithmetic<T>::value
Question 2> Does the type mean T?
Question 3> Is it true that boost::is_arithmetic<T>::value is only used to filter non-arithmetric and the function in fact only needs T?
Question 4> How to read the following statement?
template <typename T>
void dodah( T i, typename disable_if<is_integral<T> >::type* p=0 )
{
cout << "I: " << i << endl;
}
Does it mean 1> disable integral type 2> only accept non-integral type and which has embedded type as type?
Thank you
1) value is a boolean constant that will be define to true if T is arithmetic which in my version of boost means integral or float type.
2) type is a typedef on T if is_arithmetic::value is true, otherwise it is not defined. Normally if type was not defined, one would think this wouldn’t compile, however as boost documentation states:
This as the effect of removing this particular template function for template resolution when T is not arithmetic.
3) Yes
4) This read, do not use this template function if T is integral for template resolution. However in the case where you call the function with a non integral type, you do not want to have to pass a dummy second parameter, hence the default value.