時代はBoost.Lambdaではなく、Spirit.Phoenixなのだ
実行結果: http://ideone.com/33mSjQpx
#include <boost/spirit/home/phoenix/core.hpp>
#include <boost/spirit/home/phoenix/operator.hpp>
#include <boost/spirit/home/phoenix/scope.hpp>
#include <boost/spirit/home/phoenix/bind.hpp>
#include <boost/spirit/home/phoenix/function.hpp>
#include <boost/spirit/home/phoenix/statement.hpp>
#include <string>
#include <iostream>
#include <boost/ref.hpp>
#include <boost/lexical_cast.hpp>
namespace bst = boost;
namespace p2 {
using namespace bst::phoenix;
using namespace bst::phoenix::arg_names;
using namespace bst::phoenix::local_names;
}
struct inc_t {
template<typename T>
struct result {
typedef T type;
};
template<typename T>
T operator()(T x) const {
return x + 1;
}
};
p2::function<inc_t> const inc;
int main () {
using std::cout;
using namespace p2;
int n = 42;
cout << _1(n) << '\n';
(cout << val(42) << '\n')();
(cout << (ref(n) = 24) << '\n')();
(cout << inc(_1) << '\n')(n);
cout << let (_a = _1 + _2,
_b = 5)
[ _a + _b ](n, bst::cref(13))
<< '\n';
let (_a = 0) [
for_ (nothing, _a < _1, ++_a) [
cout << if_else(_a % 15 == 0, "fizz",
if_else(_a % 3 == 0, "buzz",
bind(bst::lexical_cast<std::string, int>, _a)))
<< ' '
],
ref(cout) << '\n'
](bst::cref(15));
return 0;
}
すばらしい実力です。