for (double to_find : {102.5, 110.2}) { auto prc_info = std::lower_bound(prices.begin(), prices.end(), to_find, [](double va,const PriceInfo& info) // no known conversion for argument 1 from 'PriceInfo' to 'double' { return va > info.price; });
prc_info != prices.end() ? std::cout << prc_info->price << " at index " << prc_info - prices.begin() : std::cout << to_find << " not found"; std::cout << '\n'; } }
需要将lambda函数 捕获列表中参数位置互换
1 2 3 4 5
auto prc_info = std::lower_bound(prices.begin(), prices.end(), to_find, [](const PriceInfo& info, double va) { return va > info.price; });