List parameters

Discussion in 'C++' started by user@domain.invalid, Oct 22, 2006.

  1. Guest

    Hi,

    I try this code:

    template <typename T> inline
    T const& max(T const& a, T const& b)
    {
    return a<b?b:a;
    }

    template <typename T, ... list> inline
    T const& max(T const& a, T const& b, list const& x)
    {
    return max(a, max(b, x));
    }


    But it not compile.
    I have this message:
    "error: expected identifier before '...' token"

    I saw this sample in book "c++ templates: the complete guide"
    i use wxWidgets with gcc compiler.

    Is this code legal? is it compile?
    If no how use list parameters in template?

    Thunks
    , Oct 22, 2006
    #1
    1. Advertising

  2. David Harmon Guest

    On Sun, 22 Oct 2006 02:06:20 +0200 in comp.lang.c++,
    lid wrote,
    > template <typename T, ... list> inline
    > T const& max(T const& a, T const& b, list const& x)
    > {
    > return max(a, max(b, x));
    > }


    No, the ... is not at all allowed there.
    This is from chapter 13, "Future Directions", where the authors are
    discussing things that don't exist yet, but might in the future,
    right???
    David Harmon, Oct 22, 2006
    #2
    1. Advertising

  3. Lahsen Guest

    David Harmon a écrit :
    > On Sun, 22 Oct 2006 02:06:20 +0200 in comp.lang.c++,
    > lid wrote,
    >
    >> template <typename T, ... list> inline
    >> T const& max(T const& a, T const& b, list const& x)
    >> {
    >> return max(a, max(b, x));
    >> }

    >
    >
    > No, the ... is not at all allowed there.
    > This is from chapter 13, "Future Directions", where the authors are
    > discussing things that don't exist yet, but might in the future,
    > right???
    >


    Ok,
    Thunks.

    I try to do it with typeListe technique in modern c++.

    But there'is function ellipsis like:

    void f(int ...);

    f(1, 2, 3);
    f(45, 68 ,2 ,64 ,3598);

    that compile. But it's not easy to use argument of this function.
    Lahsen, Oct 22, 2006
    #3
  4. loufoque Guest

    Lahsen wrote:
    >
    > But there'is function ellipsis like:
    >
    > void f(int ...);
    >
    > f(1, 2, 3);
    > f(45, 68 ,2 ,64 ,3598);
    >
    > that compile. But it's not easy to use argument of this function.


    That's a runtime thing which isn't type-safe at all.
    It should be avoided.
    loufoque, Oct 22, 2006
    #4
  5. loufoque Guest

    lid wrote:
    > Hi,
    >
    > I try this code:
    >
    > template <typename T> inline
    > T const& max(T const& a, T const& b)
    > {
    > return a<b?b:a;
    > }
    >
    > template <typename T, ... list> inline
    > T const& max(T const& a, T const& b, list const& x)
    > {
    > return max(a, max(b, x));
    > }
    >
    >
    > But it not compile.


    You might want to play around with variadic templates, a proposal for
    the next C++ standard which will allow what you want.
    There is already a patch to implement it in GCC.
    loufoque, Oct 22, 2006
    #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. Jonck van der Kogel
    Replies:
    2
    Views:
    967
    Jonck van der Kogel
    May 27, 2004
  2. roopa
    Replies:
    6
    Views:
    727
    Jerry Coffin
    Aug 27, 2004
  3. Jason
    Replies:
    2
    Views:
    495
    Jonathan Mcdougall
    May 13, 2006
  4. kito
    Replies:
    2
    Views:
    406
  5. Florian Loitsch
    Replies:
    11
    Views:
    242
    Michael Winter
    Mar 15, 2005
Loading...

Share This Page