![]() |
Home | Libraries | People | FAQ | More |
同様に対応するヘルパ関数も提供する。
しかし、function object traits を 使用しているおかげで、このライブラリのアダプタと接続する場合、このアダプ タを使う必要は無い。しかしながら、あなたの実装が我々の特性クラスと共 にきちんと働かない場合 (部分特殊化版が欠けていることによる) や、サードパー ティの関数オブジェクトアダプタと共に使いたい場合に、使う必要があるかもし れない。
これらのアダプタを使う必要がある場合、使い方は標準関数ポインタアダプ タと同様である。例えば、
bool bad(std::string foo) { ... } ... std::vector<std::string> c; ... std::vector<std::string>::iterator it = std::find_if(c.begin(), c.end(), std::not1(boost::ptr_fun(bad)));
しかしながら、このライブラリは関数オブジェクト特性をサポートする、強 化された ネゲータ を含んでいることに注意しな さい。それで、以上のソースと同様に以下のように書ける。
std::vector<std::string>::iterator it = std::find_if(c.begin(), c.end(), boost::not1(bad));
標準は
template <class Arg, class Result> class pointer_to_unary_function : public unary_function<Arg, Result> { public: explicit pointer_to_unary_function(Result (* f)(Arg)); Result operator()(Arg x) const; };
しかしながら、引数を代わりに
つまり、
Boost の
Result operator()(typename call_traits<Arg>::param_type x) const
我々は望ましい結果を引き出した - 参照の参照を生み出すことなく、効率性 を得たのだ。
call traits テンプレートはこの改良を実現するために使われる関数オブジェ クト特性と call_traits の両方が部分特殊化版に頼っているので、この改良は部 分特殊化の機能を持つコンパイラでのみ有効である。そうでないコンパイラでは、 関数に渡される引数は常に参照渡しとなるので、参照の参照の可能性を生みだす ことになる。
Copyright © 2000 Cadenza New Zealand Ltd. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
Revised 28 June 2000
Japanese Translation Copyright (C) 2003 shinichiro.h <g940455@mail.ecc.u-tokyo.ac.jp>.
オリジナルの、及びこの著作権表示が全ての複製の中に現れる限り、この文書の 複製、利用、変更、販売そして配布を認める。このドキュメントは「あるがまま」 に提供されており、いかなる明示的、暗黙的保証も行わない。また、 いかなる目的に対しても、その利用が適していることを関知しない。