limiting class template parameters

K

Kartsev

hello!

how to limit class template parameter T in



template <class T> SomeClass { /*.... */ }



to integral numeric types?



thanx a lot :)

hello!

how to limit class template parameter T in



template <class T> SomeClass { /*.... */ }



to integral numeric types?
 
A

Alf P. Steinbach

how to limit class template parameter T in
template <class T> SomeClass { /*.... */ }
to integral numeric types?

#define STATIC_ASSERT( expr ) ... // Your favorite STATIC_ASSERT.

template< typename T >
struct IsIntegralType
{
enum{ yes = (static_cast<T>(1)/2 == 0) };
};

template< typename T >
class SomeClass
{
private:
STATIC_ASSERT( IsIntegralType<T>::yes );
public:
...
};
 
M

Mike Wahler

Kartsev said:
hello!

how to limit class template parameter T in



template <class T> SomeClass { /*.... */ }



to integral numeric types?

if(!std::numeric_limits<T>::is_integer)
throw("no no!");

I'm not sure if this restriction can be
imposed at compile time (I can't think
of a way right now.)


-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,631
Members
45,338
Latest member
41Pearline46

Latest Threads

Top