'new' template usage

Discussion in 'C++' started by adrian.hawryluk@gmail.com, Mar 7, 2007.

  1. Guest

    Hi everyone,

    I've been using templates for a while, but I'm not at full power yet
    (knowledge=power) ;). Does anyone know where I can get information on
    this 'new' template usage?

    template<a (b, c, d)>

    Does one define it like:

    template<typename A (typename B, typename C, typename D)>
    {templated class/function definition here}

    What is its use?

    I also think that I've heard that ellipsis can also be used in the
    template list. Is this true? If so, how is it used, and for what
    purpose?

    Thanks all,


    Adrian
    , Mar 7, 2007
    #1
    1. Advertising

  2. Piyo Guest

    wrote:
    > Hi everyone,
    >
    > I've been using templates for a while, but I'm not at full power yet
    > (knowledge=power) ;). Does anyone know where I can get information on
    > this 'new' template usage?
    >
    > template<a (b, c, d)>
    >
    > Does one define it like:
    >
    > template<typename A (typename B, typename C, typename D)>
    > {templated class/function definition here}
    >
    > What is its use?
    >
    > I also think that I've heard that ellipsis can also be used in the
    > template list. Is this true? If so, how is it used, and for what
    > purpose?
    >
    > Thanks all,
    >
    >
    > Adrian
    >

    Hi Adrian,

    The new template usage that you are referring to is not part of
    the template standards of C++ I think. You will probably need to
    verify it for yourself in comp.std.c++. Having said that, that
    template syntax is used by <boost/function.hpp>. The boost people
    use boost::preprocessor (a preprocessor meta-programming library)
    that essentially uses very nifty preprocessor tricks to map

    foo<int (float, double)> to a proper looking template like
    template<typename T1, typename T2, typename T3>
    class foo;

    You can see it is action for yourself if you look inside
    boost::function. I like the work they did on it and find it
    pretty awesome for them to use macros to help create partial
    template specializations on the fly. As to what is the use of
    this type of programming, well, boost::function sums it up
    pretty nicely. I hope that answers your first question.

    For the ellipsis, again, I am not sure but once more I think that
    the "..." syntax has not yet be standardized. You will need to
    verify it for yourself. What is its use? Imagine this:

    I would like to write a max function that takes in arbitrary
    number of parameters like so

    template<typename T1, typename T2, ..., typename TN>
    max( T1 &a, T2 &b, ..., TN &z );

    this way, I can now call it like this

    max( 1, 2, 3 ); or
    max( 1.0, 2.0, 3.0, 4.5 );

    Now having said that, looking again at boost function we notice that
    it requires arbitrary number of arguments also. Yet using a combination
    of nifty tricks, they are able to circumvent the problem that the
    "..." syntax is unavailable. So it makes me wonder if the "..." syntax
    is merely a convenience for the current ways to make it work.

    You'll probably get more mileage if you post on the c++ standards
    boards instead :)

    But I hope I helped by giving you a better idea where templates can
    go in the future. :)
    Piyo, Mar 7, 2007
    #2
    1. Advertising

  3. On 7 Mar, 01:11, wrote:
    > Hi everyone,
    >
    > I've been using templates for a while, but I'm not at full power yet
    > (knowledge=power) ;). Does anyone know where I can get information on
    > this 'new' template usage?
    >
    > template<a (b, c, d)>
    >
    > Does one define it like:
    >
    > template<typename A (typename B, typename C, typename D)>
    > {templated class/function definition here}
    >
    > What is its use?
    >
    > I also think that I've heard that ellipsis can also be used in the
    > template list. Is this true? If so, how is it used, and for what
    > purpose?


    I'm sorry to say (since I'd like to have them) that neither of those
    are part of the current standard but may be part of the next (the
    ellipsis thing I'm quite sure of, but the first I don't know). The
    problem with this is that since they are not part of any standard yet,
    which means that there probably are no compilers supporting it. And if
    there are the functionality of those constructs might change until
    they have been standardized.

    As I understand things they hope to have the new standard out and
    approved by 2009, which means that most things will have settles
    sometime by 2008 and widespread compiler support should probably not
    be expected until 2010 or later. Worst case scenario would be that
    they can't agree about how something is supposed to work and throw it
    out of the standard to be part of a separate TR or the next version.
    So my advice is to not bother with these kinds of things for at least
    a year in any serious project. You can of course play around to stay
    up to date.

    For more information about what will/might be in the next standard see
    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2142.html

    --
    Erik Wikström
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Mar 7, 2007
    #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. metfan
    Replies:
    2
    Views:
    4,825
    Robert Olofsson
    Oct 21, 2003
  2. Colin J. Williams

    Webchecker Usage - a problem with local usage

    Colin J. Williams, Feb 25, 2004, in forum: Python
    Replies:
    1
    Views:
    511
    Colin J. Williams
    Feb 26, 2004
  3. hvt
    Replies:
    0
    Views:
    1,184
  4. hvt
    Replies:
    0
    Views:
    1,441
  5. Krist
    Replies:
    8
    Views:
    6,304
    Arne Vajhøj
    Feb 10, 2010
Loading...

Share This Page