1

次のコードがコンパイルされない理由:

int main() {
  map<int, int> m  = { {1, 2}, {3, 4}};

  auto p = std::min(m.begin(), m.end(), [](const map<int, int>::value_type& a, const map<int, int>::value_type& b)         { return a.second < b.second;});

  std::cout << (p->second) << std::endl;
}

エラーは次のとおりです。

X.cc:11:114: note: main()::<lambda(const value_type&, const value_type&)>
X.cc:11:114: note:   no known conversion for argument 1 from 'const std::_Rb_tree_iterator<std::pair<const int, int> >' to 'const value_type& {aka const std::pair<const int, int>&}'

ここで何が間違っていますか?それがベクトル、たとえば int のベクトルである場合、実行できたはずです。

[](int a, int b){return a<b;}

ここで同じことができないのはなぜですか?

4

2 に答える 2