8. Relation to other Boost libraries

8.1. Boost Function

˥ե󥯥ѿ˳ǼԹΤ礬롣 Ǥñʦ˥ե󥯥ηǤäƤ⡢Ĺˤ ơŪˤϦ˥ե󥯥ηѿ뤳Ȥϼ¸ԲǽǤ롣 Boost Function 饤֥ [function] ϡ㤨Ц˥ե󥯥Τ褦Ǥդδؿ֥ȤΥåѤ롣 ΥåѤηϵҤ䤹 ʲ򼨤

boost::function<int(int, int)> f = _1 + _2;
boost::function<int&(int&)> g = (_1 += 10);
int i = 1, j = 2;
f(i); // returns 3
g(i); // sets i to = 11;
åפؿ֥Ȥ֤ͤȰηϡåѥƥץ졼 boost::function Υƥץ졼ȰȤŪ˵ҤʤФʤʤ åפؿʤŪʰȤȤǤäƤƱͤǤ롣 boost::function Ǵؿ֥Ȥåפȡ۴ؿνƱʥѥեޥ󥹤ΥȤƤޤ ºݤˤϲ۴ؿѤƤ櫓ǤϤʤ ޤboost::function ˦˥ե󥯥Ǽ뤳ȤϴθȤʤꤦ롣 Φ˥ե󥯥ϡ˼ΰΥԡȤˡ«ѿؤλȤǼƤ뤫⤷ʤ SLT 르ꥺθƽФλľ˦˥ե󥯥˴뤿ᡢSTL 르ꥺθƽФǡŪʦ˥ե󥯥Υ֥ȤѤƤϾ˰Ǥ롣 boost::function ˥åפ줿˥ե󥯥ϡ¸³뤫⤷ʤ̵ʻȤIJǽäƤޤΤǤ롣 ʲˡ򼨤
int* sum = new int();
*sum = 0;
boost::function<int&(int)> counter = *sum += _1;
counter(5); // ok, *sum = 5;
delete sum; 
counter(3); // error, *sum does not exist anymore

8.2. Boost Bind

Boost Bind [bind] 饤֥ʬŪ BLL εǽȽʣ롣 ŪˤϡBoost Bind 饤֥(ʹ BB)ǤϡBLL ΰ bind ƤȤ롣 Ḥ̂Ū˰ۤʤʬ⤢롣

BLL BB ̡ȯŸۤäȤʤäƤ롣 ΤᡢBB bind BLL bind ¾ηΦ˼ǤϻѤ뤳ȤϤǤʤ ƱͤˡBB ˤ BLL bind Ѥ뤳ȤϤǤʤ BB 饤֥̾ϡ̾ boost ¸ߤΤФ BLL ̾ϡ̾ boost::lambda ¸ߤ뤿ᡢ ĤΥ饤֥϶¸Ǥ롣

BLL Ϥ C++ ɸ˽ʥѥ餬ɬפǤΤФ BB 饤֥Ϥݡ֥ʥѥǽʬǤꡢ¿Υѥǵǽ롣

ʹߤĤΥ֥Ǥϡ BB BLL ˤ bind ΰ̣ŪˤĤ롣

8.2.1. First argument of bind expression

BB ˤƤϡоݤδؿǤ bind ΰϡ ¾ΰΰȤϰۤʤ롣 ΰ˴ؤƤϡԤʤʤΤǤ롣 BLL ˤƤϡˤƤ̰Ϥʤ ʲ򼨤
template<class F>
int foo(const F& f) {
  int x;
  ..
  bind(f, _1)(x);
  ...
}
int bar(int, int);
nested(bind(bar, 1, _1));
foo bind ϼΤ褦ˤʤ롣
bind(bind(bar, 1, _1), _1)(x)
BLL ˤƤϡϼΤ褦˲ᤵ롣
bar(1, x)(x)
BB ˤƤϼΤ褦ˤʤ롣
bar(1, x)
BLL ǤϤεǽ¸뤿ᡢSection 5.9.1.1 褦ˡؿ foo bind ϼΤ褦˽񤯤ȤǽǤ롣
bind(unlambda(f), _1)(x);

BLL ǤϻĤΥץ졼ۥƤʤΤФ BB 饤֥϶ĤޤǤΥץ졼ۥ򥵥ݡȤƤ롣 ʾΥץ졼ۥ󶡤ʤϡʤ STL 르ꥺǼǤؿ֥Ȥκ¿ΰοĤǤ뤳ȤǤ롣 BB 饤֥ˤƥץ졼ۥοϴñä뤳ȤǤ롣 BLL ǤǽǤ뤬¿ϫϤɬפȤ롣 BLL ϼ°Ū˦˥ե󥯥ˤΤޤϤƤꡢ ץ˥åפϤʤ ϡѤƤ뤤ĤΥѥ餬Ŭˤ֤Υץ뤳ȤǤʤǤ롣 ֤Υץϥѥեޥ󥹤˽ʱƶͿƤޤ äˡñ(ƺǤ̤)˥ե󥯥ξˤϽפǤ롣 ơ¿Υץ졼ۥǽǤ뤬ñʦ˥ե󥯥Υѥեޥ󥹤˴ؤŶʤƤ򤷤