partial template specialization

Discussion in 'C++' started by Andrew Tomazos, Jan 6, 2012.

  1. template<class T, bool signedness>
    void f2(T);

    template<class T>
    void f2<T, true>(T t)
    {
    ... do something with signed integer
    }

    template<class T>
    void f2<T, false>(T t)
    {
    ... do something with unsigned integer
    }

    template<class T>
    void f(T t)
    {
    f2<T,numeric_limits<T>::is_signed>(t);
    }

    Compiler says no partial specialization.

    How do I do what I'm trying to do? :)
    -Andrew.
     
    Andrew Tomazos, Jan 6, 2012
    #1
    1. Advertising

  2. Andrew Tomazos <> wrote:
    > Compiler says no partial specialization.
    >
    > How do I do what I'm trying to do? :)


    Support for partial specialization of functions was not in the old
    C++ standard but is supported in the new one. If you want to make it
    work, you'll have to start using a compiler (or compiler setting) that
    supports the newer standard.
     
    Juha Nieminen, Jan 6, 2012
    #2
    1. Advertising

  3. Andrew Tomazos

    Marc Guest

    Juha Nieminen wrote:

    > Andrew Tomazos <> wrote:
    >> Compiler says no partial specialization.
    >>
    >> How do I do what I'm trying to do? :)


    Closest to what you are trying:
    template<bool b> struct Help {
    static ...
    };
    template<> struct Help<true> {
    static ...
    };
    And call Help<...>::function(...) from your wrapper.

    You could also use overloading and enable_if instead.

    > Support for partial specialization of functions was not in the old
    > C++ standard but is supported in the new one.


    Really? I don't remember hearing of such a change, and gcc/clang still
    reject partial specialization of functions.
     
    Marc, Jan 6, 2012
    #3
  4. On 1/6/2012 4:21 AM, Juha Nieminen wrote:
    > Andrew Tomazos<> wrote:
    >> Compiler says no partial specialization.
    >>
    >> How do I do what I'm trying to do? :)

    >
    > Support for partial specialization of functions was not in the old
    > C++ standard but is supported in the new one. [..]


    In faint hopes that you're not confusing "partial ordering" for "partial
    specialization", could you please quote the Standard on that? Thanks!

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jan 6, 2012
    #4
  5. Victor Bazarov <> wrote:
    > On 1/6/2012 4:21 AM, Juha Nieminen wrote:
    >> Andrew Tomazos<> wrote:
    >>> Compiler says no partial specialization.
    >>>
    >>> How do I do what I'm trying to do? :)

    >>
    >> Support for partial specialization of functions was not in the old
    >> C++ standard but is supported in the new one. [..]

    >
    > In faint hopes that you're not confusing "partial ordering" for "partial
    > specialization", could you please quote the Standard on that? Thanks!


    I was probably confusing it with default template parameters. My bad.
     
    Juha Nieminen, Jan 6, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chandra Shekhar Kumar

    template partial specialization

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    17
    Views:
    3,032
    tom_usenet
    Jun 25, 2003
  2. Joseph Turian
    Replies:
    2
    Views:
    468
  3. toton
    Replies:
    1
    Views:
    616
  4. vj
    Replies:
    1
    Views:
    485
  5. Hizo
    Replies:
    17
    Views:
    689
    itaj sherman
    Mar 7, 2011
Loading...

Share This Page