More complex expression template

Discussion in 'C++' started by PengYu.UT@gmail.com, Nov 6, 2005.

  1. Guest

    Hi,

    I read Klaus Kreft & Angelika Langer's C++ Expression Templates: An
    Introduction to the Principles of Expression Templates at
    http://www.angelikalanger.com/Articles/Cuj/ExpressionTemplates/ExpressionTemplates.htm

    It provide an express template for only one argument (see Listing 19
    and so on), which can be used to do numerical integral.

    I'm wondering how to generalize it to handle multiple arguments.

    Say, I change the definition of Identity in Listing 19 such that it
    have one `int' template argument. Then I have
    Identity<1> x;
    Identity<2> y;
    Identity<3> z;

    (x * y) and (y * z) should return two functions each of which accepts 2
    arguments. But ((x * y) * (y * z)) should return a function which
    accept 3 (not 4) arguments(and the arguments should be in the order of
    x, y, z).

    If you know anyone have implement this kind of expression template,
    would you please share with me. Or if you can give me some hints on how
    to define this expression template, it will helpful as well.

    Thanks,
    Peng


    Best wishes,
    Peng
     
    , Nov 6, 2005
    #1
    1. Advertising

  2. * :
    >
    > I read Klaus Kreft & Angelika Langer's C++ Expression Templates: An
    > Introduction to the Principles of Expression Templates at
    > http://www.angelikalanger.com/Articles/Cuj/ExpressionTemplates/ExpressionTemplates.htm
    >
    > It provide an express template for only one argument (see Listing 19
    > and so on), which can be used to do numerical integral.
    >
    > I'm wondering how to generalize it to handle multiple arguments.
    >
    > Say, I change the definition of Identity in Listing 19 such that it
    > have one `int' template argument. Then I have
    > Identity<1> x;
    > Identity<2> y;
    > Identity<3> z;
    >
    > (x * y) and (y * z) should return two functions each of which accepts 2
    > arguments. But ((x * y) * (y * z)) should return a function which
    > accept 3 (not 4) arguments(and the arguments should be in the order of
    > x, y, z).


    Personally I'd go for

    template< T > T foo( T x, T y, T z ) { return x*y*y*z; }

    I think the "readability" of inline expressions, which is their only
    reason for existence, is nothing of the sort: a well-chosen function
    name conveys much more and more clearly than a cryptic expression.

    But see

    <url: http://www.boost.org/doc/html/apa.html#lambda.why_weak_arity>.


    > If you know anyone have implement this kind of expression template,
    > would you please share with me. Or if you can give me some hints on how
    > to define this expression template, it will helpful as well.


    I remember reading about it. You'll have to do the equivalent of a set
    union for the argument types. A bitvector (or that sort of encoding,
    limiting the possible argument types) might just be the thing. But the
    result would, IMHO, probably just be an expression utility that allows
    you to write even more unreadable and cryptic expressions. Now what's
    the arity here...

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Nov 6, 2005
    #2
    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. news.amnet.net.au
    Replies:
    1
    Views:
    581
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    749
    Stanimir Stamenkov
    Oct 25, 2005
  3. Michael
    Replies:
    4
    Views:
    417
    Matt Hammond
    Jun 26, 2006
  4. howa
    Replies:
    17
    Views:
    589
    ~kurt
    Jul 1, 2007
  5. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    218
    Jeff Wood
    Sep 29, 2005
Loading...

Share This Page