Boost logo

Boost :

From: Jaakko Järvi (jaakko.jarvi_at_[hidden])
Date: 2000-03-23 06:26:27


Hello,

First, sorry for the late reply, I was on vacation and offline for a
week.

Thanks to Jeremy for the fixes to make KCC eat the library.
I'll include them to the release in lambda.cs.utu.fi page as well.

Jeremy spotted a problem related to the parameter types in the apply
functions.

I'll repeat a short version of Jeremy's description.

>
> Here's the error message:
>
> "../ll/binder_base.hpp", line 244: warning: temporary used for
initial value
> of reference to non-const (anachronism)
> select(get<1>(args), a, b, c),
> ^

> and the error is triggered from this line
>
> placeholder_basics.cpp:
>
> cout << "(free1 + free2 + free3)(i, j, k) = " << (free1 + free2 +
free3)(i, j, k) << "\n\n";
>

> So I think the problem is that when (free1 + free2 + free3) gets
> evaluated, the result of the first addition returns a temporary
> (an "int" in this case), which is then passed to the apply()
> function.
>
> +
> / \
> temp -> + f3
> / \
> f1 f2
>
> The apply function takes references, resulting in the warning about
> passing temporaries to references.
>
> #define LL_BINARY_ACTION(OPER_SYMBOL, GROUP, OPER_NAME) \
> template<> struct GROUP##<OPER_NAME> {\
> template<class RET, class A, class B>\
> RET static apply(A& a, B& b) { return a OPER_SYMBOL b; }\
> };\
> \

A central idea in the return type deduction system of LL is that
whenever the return type is some non-reference type T, the LL deduces
the return type to "const T". Hence, the select function call above
returns an object of type "const int" rather than "int".

The apply function:

  template<class RET, class A, class B>
  RET static apply(A& a, B& b) { return a OPER_SYMBOL b; }

takes it's parameters by reference, otherwise the types are deduced.
Hence, in the case described above, the apply function is called with a
temporary of type "const int". Type A is deduced to "const int" and
thus a temporary is not bound to a non-const reference.

Hence, I think the compiler should not complain. This seems to be the
view of gcc. Apparently KCC interpretation is different. I do not have
a very recent version of KCC available, so Jeremy, it would be nice if
you could test this further.

(Note, that there is a bug in the type deduction code, which causes the
select function to return a non-const temporary from artihmetic
operations between a long and unsigned int. However, this does not show
up with the placeholder_basics.cpp file.)

/Jaakko


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk