I want to use an any_cast within a lambda expression. Searching for
ll_any_cast didn't bring up anything.
So, the first attempt was to bind to the overloaded any_cast function
with a function pointer cast. This worked, but was ugly and unreadable.
The second attempt is to write ll_any_cast using ll_static cast as a
starting point. The problem here is that
cast_actionstd::string >::apply() passes an any
containing a lambda placeholder to the any_cast instead an any
containing the string. So, that's where I'm stuck at the moment. Below
is what I have so far with two call stacks. One for ll_static_cast and
the other for ll_any_cast.
namespace boost {
namespace lambda {
template<class T> class any_cast_action;
template<class T> class cast_action
{
public:
template
static RET apply(Arg1 &a1) {
return any_cast<RET>(a1);
}
};
// any_cast
template <class T>
inline const lambda_functor<
lambda_functor_base<
action<1, cast_action >,
tuple
>
>
ll_any_cast(const any& a1) {
return
lambda_functor_base<
action<1, cast_action >,
tuple
>
( tuple(a1));
}
} // namespace lambda
} // namespace boost
BOOST_AUTO_TEST_CASE(ll_any_cast_test)
{
std::string msg0("Hello");
std::string msgO("Robert");
boost::any many = msg0;
std::string msg1 = any_cast<string>(many) + " " + msgO;
std::string msg2 = (ll_static_cast<string>(_1) + " " + _2)(msg0,
msgO);
std::string msg3 = (ll_any_cast<string>(_1) + " " + _2)(many, msgO);
BOOST_CHECK_EQUAL(msg1, "Hello Robert");
BOOST_CHECK_EQUAL(msg1, msg2);
BOOST_CHECK_EQUAL(msg1, msg3);
}
SHUnitTests.exe!
boost::lambda::cast_action > >::apply,std::basic_string >(std::basic_string & a1="Hello") Line 41 C++
SHUnitTests.exe!
boost::lambda::lambda_functor_base > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >::call,std::basic_string,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(std::basic_string & a="Hello", std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 403 + 0x38 bytes C++
SHUnitTests.exe!
boost::lambda::detail::select > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >,std::basic_string,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functor > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > > & op={...}, std::basic_string & a="Hello", std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 30 + 0x1c bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functor_baseboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >::call,std::basic_string,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(std::basic_string & a="Hello", std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::detail::selectboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >,std::basic_string,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functorboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > > & op={...}, std::basic_string & a="Hello", std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 30 + 0x1c bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functor_baseboost::lambda::plus_action,boost::tuples::tupleboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,boost::lambda::lambda_functor >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >::call,std::basic_string,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(std::basic_string & a="Hello", std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functorboost::lambda::plus_action,boost::tuples::tupleboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,boost::lambda::lambda_functor >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >::operator(),std::basic_string >(std::basic_string & a="Hello", std::basic_string & b="Robert") Line 191 + 0x1e bytes C++
SHUnitTests.exe!ll_any_cast_test::test_method() Line 660
+ 0x57 bytes C++
SHUnitTests.exe!
boost::lambda::cast_action > >::apply,boost::any const >(const boost::any & a1={...}) Line 628 C++
SHUnitTests.exe!
boost::lambda::lambda_functor_base > > >,boost::tuples::tuple >::call,boost::any,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(boost::any & a={...}, std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 403 + 0x5e bytes C++
SHUnitTests.exe!
boost::lambda::detail::select > > >,boost::tuples::tuple >,boost::any,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functor > > >,boost::tuples::tuple > > & op={...}, boost::any & a={...}, std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 30 + 0x1c bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functor_baseboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >::call,boost::any,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(boost::any & a={...}, std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::detail::selectboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >,boost::any,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functorboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > > & op={...}, boost::any & a={...}, std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 30 + 0x1c bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functor_baseboost::lambda::plus_action,boost::tuples::tupleboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,boost::lambda::lambda_functor >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> >::call,boost::any,std::basic_string,boost::tuples::null_type const ,boost::tuples::null_type const >(boost::any & a={...}, std::basic_string & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functorboost::lambda::plus_action,boost::tuples::tupleboost::lambda::plus_action,boost::tuples::tuple > > >,boost::tuples::tuple > >,char const (&)[2],boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >,boost::lambda::lambda_functor >,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type> > >::operator() >(boost::any & a={...}, std::basic_string & b="Robert") Line 191 + 0x1e bytes C++
SHUnitTests.exe!ll_any_cast_test::test_method() Line 661
+ 0xbf bytes C++