tieで初期化させろ


#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/tuple/rem.hpp>
#include <boost/preprocessor/seq/fold_left.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>

template<size_t N, typename T>
typename std::tuple_element<N, T>::type & get_with_tuple_ref_collapsing(T & tup) {
return std::get<N>(tup);
}
template<size_t N, typename T>
typename std::tuple_element<N, T>::type && get_with_tuple_ref_collapsing(T && tup) {
return std::move(std::get<N>(tup));
}

#define TIE(seq, expr) TIE_I(seq, expr, __LINE__,)
#define TIE_AUTO(seq, expr) TIE_I(seq, expr, __LINE__, auto)

#define TIE_I(seq, expr, id, a) TIE_II(seq, expr, id, a)
#define TIE_II(seq, expr, id, a) auto && tie_tmp_ ## id = expr; BOOST_PP_TUPLE_ELEM(4, 3, BOOST_PP_SEQ_FOLD_LEFT(TIE_OP, (0, tie_tmp_ ## id , a,), seq))
#define TIE_OP(_, l, e) TIE_OP_I)((e, BOOST_PP_TUPLE_REM(4)l))(
#define TIE_OP_I(par) TIE_OP_II par
#define TIE_OP_II(e, n, name, a, s) (BOOST_PP_INC(n), name, a, s a e(get_with_tuple_ref_collapsing<n>(std::forward<decltype(name)>(name)));)

// まとめて宣言して初期化
TIE)((int n)(int m), f())(

// 宣言する全ての変数の型を自動推論で
TIE_AUTO)((x)(y)(z), g())(

展開結果:http://codepad.org/4A0tCzrA
なんかこんな感じで。Boost.PPは楽でよいです。なんか右辺値とか左辺値とかの参照がややこしかったけど、今になってこの一言はすばらしいと感じた。やっぱりね最後に辿っちゃうのはくらいおらいとさんですね。

追記 2010/2/17
foldingよりcollapsingのほうがよさげなので直しときました。