Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-09-19 16:45:57

Jaap Suter wrote:
> However, consider the following case:
> apply_if< some_condition,
> some_type_1,
> plus< some_type_2::type, some_number >
> >::type
> In this case, I get the impression that my compiler (Intel)
> evaluates the template parameters of plus, and thus of some_type_2::type,
> even when it is not used.

It does indeed.


> Thus, I provide the following indirection:
> template< ... >
> struct recurse
> {
> typedef plus< some_type_2::type, some_number > type
> };
> apply_if< some_condition,
> some_type_1,
> recurse
> >::type
> And now it works, because the compiler no longer evaluates the
> some_type_2::type, if it is not needed.
> Now, I have the following questions:
> 1. Can you acknowledge this problem? The fact that the
> compiler evaluates template parameters for non-used types,
> and consequently that the mpl::apply_if rationale applies here
> as well?


> 2. Is this the best solution to solve this problem?

I've been inclining towards something like this:

    typedef apply_if<
        , some_type_1
        , lazy< plus< apply0<some_type_2>, some_number > >
>::type f;

The parameter of lazy<...> template is basically a lambda expression, but
without any placeholders; I haven't got to implementing it yet, though.

> 3. Maybe we can introduce the indirection in plus and other
> meta-functions that act on integral constants directly.

I am afraid it's not such a good idea as it might seem at the first sight -
please see my reply to Terje.

> Anyway, just some questions, comments and ideas....

Thanks for raising the issue - it definitely needs to be solved.


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