1

2 つの std::maps をマージする次のコードがあります。

template <typename key, typename value>
  void merge_maps(std::map<key, value>& one, const std::map<key, value>& another,
    boost::function2<value, value, value> aggregate)
  {
    // MERGING. aggregate is called if key exists in both maps
  }

このような構造体があります。

  struct foo {
    int bar;
    foo operator+(const foo& other) const;
  };

std::map<std::wstring, foo> one, anotherを使用foo::operator+して渡した2 つをマージしようとしましboost::lambdaたが、コンパイル エラーが発生しました。

  merge_maps(one, another, _1+_2); // MSCV9.0 cannot deduce template argument for lambda there

お願い助けて。私が間違っていることは何ですか?

4

1 に答える 1

0

解決しました。ラムダリターンタイプを指定する必要がありました。MSVCは、問題なくテンプレートをインスタンス化します。

merge_maps(one, another, ret<foo>(_1+_2));
于 2012-09-24T19:00:03.213 に答える