
Hi Joel,
the question is what do I have to do to be able to use the following syntax instead _1 + llnorm(_2)
Lambdadoes not have such a facility. You can use Phoenix instead. Phoenix (lazy) functions allow you to do that. Phoenix is intended to supercedeLambda. Phoenix has been reviewed and is conditionally accepted into Boost after another mini-review.
Ok, I gave up with Boost.Lambda for defining such "lazy function" and
used Phoenix instead. The process was quite painless. Below is the
(working) code to define a lazy complex modulus function for those who
are interested. I have still two concerns though:
1) I am worried how the lazy function can figure out which version of
std::norm<T> to call to obtain the right result. For
std::complex<double> the lazy function works fine (double is hard
coded). But for std::complex<int> it seems that the lazy function will
always convert the result to double, I couldn't make the lazy funcion
as generic as the original std::norm<T>(std::complex<T> const& c)
function. Is it possible to improve the lazy function definition in
that respect?
(BTW, for std::complex, T == std::complex<T>::value_type)
(It is not that I think std::complex<int> is useful for something but
I thing it is a good example to ask about this).
2) I may be asking for too much sugar but is there a way to name the
function "std::norm" and not have conflicts with the standard
"std::norm<T>(std::complex<T> const& c)", the best I could do was to
call it std::norm_;
The following is the working example, compares the Lambda version with
the Phoenix version (sum5 and sum6):
#include<vector>
#include<iostream>
#include