Hi there,
I need to make sure that a given template class is only instantiated with
integer types, and another one only with the likes of float or double.
I have played with boost::concept_check and was wondering, why it is
possible to say
BOOST_CONCEPT_ASSERT((Integer<T>));
while there is no predefined
BOOST_CONCEPT_ASSERT((FloatingPoint<T>));
The simple code below seems to do its job, so there must be some trade-off
which I do not see ?
/*************************************************************************/
#include <iostream>
#include
#include
#include
#include
/*****************************************************************/
namespace boost
{
BOOST_concept(FloatingPoint, (T))
{
BOOST_CONCEPT_USAGE(FloatingPoint)
{
x.error_type_must_be_a_floating_point_type();
}
private:
T x;
};
template <> struct FloatingPoint<long double> {};
template <> struct FloatingPoint<double> {};
template <> struct FloatingPoint<float> {};
}
/*****************************************************************/
template <class T>
class integerWrapper
{
BOOST_CONCEPT_ASSERT((boost::Integer<T>));
public:
integerWrapper() { /* nothing */ }
};
/*****************************************************************/
template <class T>
class fpWrapper
{
BOOST_CONCEPT_ASSERT((boost::FloatingPoint<T>));
public:
fpWrapper() { /* nothing */ }
};
/*****************************************************************/
main() {
integerWrapperboost::int32_t iW;
fpWrapper<double> fW_double; // o.k.
fpWrapper<float> fW_float; // o.k.
// fpWrapper<char> fW_char; // fails to compile. Good.
// fpWrapperboost::int32_t fW_int32; // fails to compile. Good
}
/*************************************************************************/
Best Regards,
Ruediger