Boost logo

Boost :

From: Ullrich Koethe (koethe_at_[hidden])
Date: 2001-03-29 12:38:28

Jeremy Siek wrote:
> On Thu, 29 Mar 2001, Ullrich Koethe wrote:
> koethe> I don't see why the result traits shouldn't be part of the algebraic
> koethe> concept definitions. After all, you always need them together.
> Oh, I didn't mean that I wouldn't add them to the requirements. I just
> meant that I'd apply the current language about convertibility, etc. to
> the type produced by the traits.

This is actually a very interesting question. I have both automatic
conversion form the promote type back to the original type, and I've
fromPromote() functions, which round and clip. It's often a tough
decision which one to use in a generic algorithm - automatic conversion
is faster, but fromPromote() is more accurate. Clear rules would be nice
to have, so that, ideally, generic algorithms could automatically choose
the most appropriate way to write back results.

> koethe> > To allow for expression templates, the result type will not only
> koethe> > depend on the operands but also on the operator. Therefore we
> koethe> > need a tag for each operator.
> koethe> >
> koethe> > struct add_tag { };
> koethe> > struct multiply_tag { };
> koethe> > ...
> koethe> >
> koethe> > and then make the operator tag a parameter to the traits class
> koethe> >
> koethe> > result_traits<OpTag,A,B>::type
> koethe> >
> koethe>
> koethe> Can you give examples where this would be necessary? I've contemplated
> koethe> this in my application domain, but it looked like an
> koethe> over-generalization.
> As I said above, this is required by expression templates.

I have implemented expression templates (and even a lambda library with
mixed operand types) without the need for operation-specific promote
traits. In fact, I can imagine that formal spcification of algebraic
concepts (including type promotion) reduces or even elimiates the need
for them. Perhaps, operation-specific promote traits are a sign that
there is a concept missing ?

> Look at Walter's matrix code.

Excuse my ignorance, but what's Walter's matrix code?

> When you add two matrices you get one type, and when
> you subtract them you get a different type. This is because the function
> being applied has to be encoded in the expression type, so that later on,
> when the expression is evaluated in the assignment, the operations can be
> performed.

As I said, perhaps the concepts are not yet quite right.


|                                                                |
| Ullrich Koethe  Universität Hamburg / University of Hamburg    |
|                 FB Informatik / Dept. of Computer Science      |
|                 AB Kognitive Systeme / Cognitive Systems Group |
|                                                                |
| Phone: +49 (0)40 42883-2573                Vogt-Koelln-Str. 30 |
| Fax:   +49 (0)40 42883-2572                D - 22527 Hamburg   |
| Email: u.koethe_at_[hidden]               Germany             |
|        koethe_at_[hidden]                        |
| WWW:      |

Boost list run by bdawes at, gregod at, cpdaniel at, john at