Boost logo

Boost :

From: Ullrich Koethe (koethe_at_[hidden])
Date: 2006-10-17 15:18:28

Hi Lubomir,

Lubomir Bourdev wrote:

> We don't believe the type of the result could automatically be inferred
> simply from the types of arguments. The optimal type depends on your
> intent and the context.

True. But the result type is usually not automatically inferred in VIGRA
(it is inferred from the destination image you passed in). Promote traits
are mainly used for the definition of intermediate types (e.g. temporary

Essentially, promotion traits make explicit what the compiler is doing
anyway. For example, the type of an expression adding two signed chars is
always int, regardless of the type of the variable the result is
ultimately assigned to. We wanted to achieve the same for the addition of
images. (We did not always get it right, but this can be corrected.)

> For example, VIGRA's promotion traits choose double as the promotion for
> int when dealing with floating point operations. Why not float? On many
> architectures float is faster, and precision may not be an issue in the
> context in which you use it.

Right, some customization would be nice. But the defaults have worked very
well for us most of the time, so we didn't feel an urgent need to change
the behavior.

> Why should int always be the result type of adding two ints?

Because that's what the C++ standard says (AFAIR).

> Int for summing two shorts
> will not overflow, but what if you are building, say, the integral image
> and you want to sum the values of all pixels in your image?

This can be handled by means of an appropriate Inspector with value_type
double or BigInt. The VIGRA Inspector concept is like a Functor, except
that it doesn't return a value, but collects some statistics about the
values it has seen. (Note that VIGRA is also defined in terms of concepts,
although not quite as nice as GIL.)

> This is why in GIL we allow the type of the result to be specified
> explicitly upon invoking the operation. Promotion traits can at best be
> useful for a reasonable default,

Resonable defaults are everything in generic programming, otherwise it's

> We feel that promotion traits belong
> in boost::type_traits and not in an image library, as the problem
> generalizes beyond images.

I agree.


|                                                                |
| Ullrich Koethe  Universitaet Hamburg / University of Hamburg   |
|                 FB Informatik        / Dept. of Informatics    |
|                 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