|
Boost : |
From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-03-11 02:28:49
A few months ago, Aleksey posted a cool way of doing lambda using function
notation. I hadn't followed the thread at the time, but I read up on it
recently. Like many others, I found it hard to understand how it worked, so
I asked Aleksey if he could make a minimal example of it, which he did.
For the benefit of anybody else interested in knowing how it works, I post
the example here. I found it much easier to understand how it works, with
such a minimal example.
--- Start ---
#include <boost/mpl/quote.hpp>
#include <boost/mpl/apply.hpp>
#include "boost/mpl/bind.hpp"
#include "boost/type_traits/is_same.hpp"
#include "boost/static_assert.hpp"
using namespace boost::mpl;
template<typename T>
struct expr
{
typedef T type;
};
template<typename F, typename T1, typename T2>
struct expr<F (T1, T2)> : bind2<F, typename expr<T1>::type, typename
expr<T2>::type> {};
struct is_same : quote2<boost::is_same> {};
// Here:
typedef apply<expr<is_same(_, int)>, int>::type type;
BOOST_STATIC_ASSERT(type::value);
--- End ---
Regards,
Terje
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk