limiting class template parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kartsev

    limiting class template parameters


    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?


    --
    Posted via http://dbforums.com
  • Alf P. Steinbach

    #2
    Re: limiting class template parameters

    On Thu, 16 Oct 2003 19:46:27 -0400, Kartsev <member31623@db forums.com> wrote:
    [color=blue]
    >how to limit class template parameter T in
    >template <class T> SomeClass { /*.... */ }
    >to integral numeric types?[/color]

    #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:
    ...
    };

    Comment

    • Mike Wahler

      #3
      Re: limiting class template parameters


      "Kartsev" <member31623@db forums.com> wrote in message
      news:3491414.10 66347987@dbforu ms.com...[color=blue]
      >
      > hello!
      >
      > how to limit class template parameter T in
      >
      >
      >
      > template <class T> SomeClass { /*.... */ }
      >
      >
      >
      > to integral numeric types?[/color]

      if(!std::numeri c_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




      Comment

      Working...