|
Boost Users : |
Subject: Re: [Boost-users] Passing lambda placeholders to functions
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-22 19:31:34
AMDG
Zachary Turner wrote:
> It seems very simple, but it's not compiling.
>
> int translate(const std::string& str)
> {
> return 0;
> }
>
> //all required using declarations are present but omitted for brevity
> //
> options_description options;
> variables_map values;
> int i;
>
> options.add_options()
> ("test", value<std::string>()->notifier(var(i) = translate(_1)));
>
> I get the following error:
>
> 'translate': cannot convert parameter 1 from
> 'boost::lambda::placeholder1_type' to 'std::string'. No user defined
> conversion operator available that can perform this conversion, or the
> operator cannot be called.
>
> Is this type of usage unsupported for some reason?
It's unsupported because C++ doesn't allow Boost.Lambda to
magically create overloads of every function that you might want to
use with it. Not to mention that if this usage did work, then trying
to pass a lambda functor to a function would be ambiguous with
trying to compose a larger lambda expression.
Use bind. http://tinyurl.com/nkhuez.
> If I change the
> variable declaration and the add_options() call to the following it
> works fine:
>
> std::string s
>
> options.add_options()
> ("test", value<std::string>()->notifier(var(s) = _1));
>
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net