【发布时间】:2021-11-23 18:21:19
【问题描述】:
它给出no instance of overloaded function "lower_bound" matches the argument list 错误。我不理解这种行为,因为大括号在制作一对时通常可以正常工作。
使用大括号:
vector<pair<int, int>> a;
auto ptr = lower_bound(a.begin(), a.end(), {2, 3});
使用 make 对:
vector<pair<int, int>> a;
auto ptr = lower_bound(a.begin(), a.end(), make_pair(2, 3));
【问题讨论】:
-
编译器如何从
{2, 3}推断出std::pair甚至在原则上?注意迭代器类型不参与这个推演:template<class ForwardIt, class T> ForwardIt lower_bound( ForwardIt first, ForwardIt last, const T& value );。 -
@Evg 所以,我需要像
std::pair<int, int>{2, 3}那样转换它吗? -
你可以说
std::pair(2, 3)。
标签: c++ stl lower-bound