partial template specialization

Discussion in 'C++' started by skscpp, Oct 1, 2003.

  1. skscpp

    skscpp Guest

    Here is the code that I currently have:

    template <typename type, typename ret>
    struct XdrFunctionType
    {
    typedef type Type;
    typedef ret (*Policy)(XDR*, Type*);
    };

    template <typename type, typename ret, typename XdrFunctionType<type,
    ret>::policy>
    struct XdrPolicy
    {
    typedef type Type;
    typedef XdrFunctionType<type, ret>::policy Policy;
    };

    =====================

    I want to specialize XdrPolicy template for ret type of bool and ret type of
    bool_t.
    In other words, I don't want the clients of XdrPolicy to have to enter 3
    template parameters but rather only two: the "type" and the "Policy"
    function. I want the "ret" type to be implicitly known somehow - is that
    possible with what I have or with slight variation from it.

    Thanks.
    skscpp, Oct 1, 2003
    #1
    1. Advertising

  2. skscpp

    Mike Wahler Guest

    "skscpp" <> wrote in message
    news:blfemf$ml3$...
    > Here is the code that I currently have:
    >
    > template <typename type, typename ret>
    > struct XdrFunctionType
    > {
    > typedef type Type;
    > typedef ret (*Policy)(XDR*, Type*);
    > };
    >
    > template <typename type, typename ret, typename XdrFunctionType<type,
    > ret>::policy>
    > struct XdrPolicy
    > {
    > typedef type Type;
    > typedef XdrFunctionType<type, ret>::policy Policy;
    > };
    >
    > =====================
    >
    > I want to specialize XdrPolicy template for ret type of bool and ret type

    of
    > bool_t.
    > In other words, I don't want the clients of XdrPolicy to have to enter 3
    > template parameters but rather only two: the "type" and the "Policy"
    > function. I want the "ret" type to be implicitly known somehow - is that
    > possible with what I have or with slight variation from it.


    Perhaps I'm misunderstanding, but note that template
    arguments can be defaulted. If you want to default
    only one of three, it needs to be last.

    template<typename A, typename B, typename C = T>

    -Mike
    Mike Wahler, Oct 1, 2003
    #2
    1. Advertising

  3. skscpp

    skscpp Guest

    "Mike Wahler" <> wrote in message
    news:7qHeb.11595$...
    >
    > "skscpp" <> wrote in message
    > news:blfemf$ml3$...
    > > Here is the code that I currently have:
    > >
    > > template <typename type, typename ret>
    > > struct XdrFunctionType
    > > {
    > > typedef type Type;
    > > typedef ret (*Policy)(XDR*, Type*);
    > > };
    > >
    > > template <typename type, typename ret, typename XdrFunctionType<type,
    > > ret>::policy>
    > > struct XdrPolicy
    > > {
    > > typedef type Type;
    > > typedef XdrFunctionType<type, ret>::policy Policy;
    > > };
    > >
    > > =====================
    > >
    > > I want to specialize XdrPolicy template for ret type of bool and ret

    type
    > of
    > > bool_t.
    > > In other words, I don't want the clients of XdrPolicy to have to enter 3
    > > template parameters but rather only two: the "type" and the "Policy"
    > > function. I want the "ret" type to be implicitly known somehow - is

    that
    > > possible with what I have or with slight variation from it.

    >
    > Perhaps I'm misunderstanding, but note that template
    > arguments can be defaulted. If you want to default
    > only one of three, it needs to be last.
    >
    > template<typename A, typename B, typename C = T>
    >
    > -Mike


    You are correct. However, my third parameter depends on my 2nd paramater.
    I guess there isn't a way to overcome this. Well, I don't necessarily have
    to use "default argument" scheme.

    Thanks.
    skscpp, Oct 1, 2003
    #3
    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,027
    tom_usenet
    Jun 25, 2003
  2. Joseph Turian
    Replies:
    2
    Views:
    462
  3. toton
    Replies:
    1
    Views:
    610
  4. vj
    Replies:
    1
    Views:
    481
  5. Hizo
    Replies:
    17
    Views:
    680
    itaj sherman
    Mar 7, 2011
Loading...

Share This Page