Imperfect C++: Practical Solutions For Real-life Programming

Imperfect C++: Practical Solutions for Real-Life Programming
Imperfect C++: Practical Solutions for Real-Life Programming
うぉ・・・.ぐぎぎ・・・.ほ,( ゜д゜)ホスィ….
以下が内容のサンプル.
http://synesis.com.au/publishing/imperfect/cpp/impcpp_chapter_34.pdf
サンプルから技法を一つ.

#include <iostream>
#include <boost/range.hpp> // From 1.32.0

int main()
{
  using namespace std;
  using namespace boost;

  struct X{
    struct local_functor
    {
      bool operator()(char const &c) const
      { return c == 'f'; }
    };
  };

  char str[] = "abcdefghijklmn";
  char *found;
  found = find_if(begin(str), end(str), X::local_functor());

  cout << found - begin(str) << endl;
}

template引数が外部リンケージを持たなくてはならないためにlocal functorをSTLアルゴリズム等に使えない,という欠点を避ける裏技.VC++などで使える.Comeau, GCC, Intelでは上のコードは通らない(通らないほうが実際は正しい).もちろんこういう個々のcompilerに特有の技法だけ論じられているわけじゃないのであしからず.
うぅむ.こんなとこ突いてくる本(C++の言語上の問題点を浮き彫りにしてそのwork-aroundを論じる本)は初めて見た・・・.