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_action<any_cast_action<std::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<any_cast_action<T> >
{
public:
template<class RET, class Arg1>
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<any_cast_action<T> > >,
tuple<typename const_copy_argument<const any>::type>
>
>
ll_any_cast(const any& a1) {
return
lambda_functor_base<
action<1, cast_action<any_cast_action<T> > >,
tuple<typename const_copy_argument<const
any>::type>
>
( tuple<typename const_copy_argument<const
any>::type>(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<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::apply<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & a1="Hello") Line 41 C++
SHUnitTests.exe!
boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & a="Hello", std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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<char,std::char_traits<char>,std::allocator<char> > & a="Hello", std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & a="Hello", std::basic_string<char,std::char_traits<char>,std::allocator<char> > & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::detail::select<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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<char,std::char_traits<char>,std::allocator<char> > & a="Hello", std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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::lambda::placeholder<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<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & a="Hello", std::basic_string<char,std::char_traits<char>,std::allocator<char> > & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::static_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,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::lambda::placeholder<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> > >::operator()<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & a="Hello", std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::apply<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::any const >(const boost::any & a1={...}) Line 628 C++
SHUnitTests.exe!
boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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<char,std::char_traits<char>,std::allocator<char> >,boost::any,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(boost::any & a={...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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> >,boost::any,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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={...}, boost::any & a={...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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<char,std::char_traits<char>,std::allocator<char> >,boost::any,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(boost::any & a={...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::detail::select<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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::any,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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={...}, boost::any & a={...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 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_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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::lambda::placeholder<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<char,std::char_traits<char>,std::allocator<char> >,boost::any,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::tuples::null_type const ,boost::tuples::null_type const >(boost::any & a={...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & b="Robert", const boost::tuples::null_type & c={...}, const boost::tuples::null_type & env={...}) Line 206 + 0x9d bytes C++
SHUnitTests.exe!
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>,boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<1,boost::lambda::cast_action<boost::lambda::any_cast_action<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >,boost::tuples::tuple<boost::any const ,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::lambda::placeholder<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> > >::operator()<boost::any,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >(boost::any & a={...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & b="Robert") Line 191 + 0x1e bytes C++
SHUnitTests.exe!ll_any_cast_test::test_method() Line 661
+ 0xbf bytes C++