I am working on a Matrix class that accepts both integral (short, int, long) and floating-point types (float, double). I want some methods to be limited only to floating point types (for example, the inversion method), and some methods should have different implementations for floating types and integral types (for example, the == operator). I have an assumption that the correct way is to use boost "enable_if" and "is_integral" / "is_floating_point", but I cannot get it to work.
My implementation is similar to this C ++ pseudo-code:
template <typename T>
class Matrix
{
...
bool operator==(Matrix<typename enable_if<is_integral<T> T >::type >) const;
bool operator==(Matrix<typename enable_if<is_floating_point<T>::type T> >) const;
typename enable_if<is_floating_point<T> T> computeInverse() const;
...
};
bool Matrix<T>::operator==(Matrix<typename enable_if<is_integral<T> T >::type >) const {
}
bool Matrix<T>::operator==(Matrix<typename enable_if<is_integral<T> T >::type >) const {
}
Matrix<typename enable_if<is_floating_point<T> T>::type > Matrix<T>::computeInverse() const {
}
This creates a lot of compilation errors, whereas I think these are the most relevant:
error: no type named ‘type’ in ‘struct boost::enable_if<boost::is_integral<float>, float>’
and
error: no type named ‘type’ in ‘struct boost::enable_if<boost::is_floating_point<int>, int>’
, , , boost enable_if, ?
, ? , , .