■
つまり、
template < typename Arg > class N { typedef Arg type; }; N<int> // ←
この瞬間は、関数に引数をbindしただけ、というところか。
N<int> // ← 引数のbind :: // ← 関数呼び出し type // ← 結果参照
eval_ifは
#include <boost/bind.hpp> #include <boost/functional.hpp> int loop( int n ) { return loop( n-1 ); } int ret0( ) { return 0; } template < typename Then, typename Else > typename Else::result_type eval_if( bool b, Then t, Else e ) { if ( b ) return t(); else return e(); } template < typename Ret > Ret if_ ( bool b, Ret then_, Ret else_ ) { if ( b ) return then_; else return else_; } int main() { /* bind( loop, 0 ) = loop<0> */ return eval_if ( true, ret0, boost::bind( loop, 0 ) ); /* return if_ ( true, ret0(), boost::bind( loop, 0 )() );*/ }
こんなふうに考えればいいんかなー。
boost::bindを生まれて初めてつかいました。