Boost logo

Boost Users :

Subject: Re: [Boost-users] naming delayed variables string in boost lamdba
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-11-11 12:46:54


OvermindDL1 wrote:
On Wed, Nov 11, 2009 at 9:24 AM, Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
  
2009/11/11 Emanuele Rocci <rocciemanuele@hotmail.com>
    
Hi All
I am getting familiar with boost::lambda.
Today I learnt about delayed variable and usage of boost::constant in
lambda expression.
Do you know why when I try to declare delayed variables for string like I
do below
the compiler gives me each time an error?
I tried the following
constant_type<const char*>::type _msg_a(constant("my msg"));
constant_type<const std::string>::type _msg_b(constant("my msg"));
constant_type<std::string>::type _msg_c(constant("my msg"));
If I use constant( "my msg" ) inside a boost lambda expression everything
is fine but I cannot declare correctly a delayed variable.
Do you know how to fix it or where I can get some details?
Thanks in advance
Mn
      
Function objects generated by lambda have unspecified types. If you want to
save them, use Boost.Function.
#include <iostream>
#include <boost/lambda/core.hpp>
#include <boost/function.hpp>
int main() {
  boost::function<const char*()> f = boost::lambda::constant("hello");
  std::cout << f() << std::endl;
}
    

Or BOOST_AUTO (which will have lower overhead then Boost.Function).
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Could you translate the example to use BOOST_AUTO in place of Boost.Function?

Ryan

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