C++11 决心<;未解析的重载函数类型>;在std::异步调用中

C++11 决心<;未解析的重载函数类型>;在std::异步调用中,c++11,asynchronous,C++11,Asynchronous,无法解析从std::async调用std::lower_bound的此实例。例如: #include <vector> #include <algorithm> #include <future> #include <iostream> int main() { std::vector<int> v = {1,3,4,6,7}; auto res = std::async(std::launch::async, std::lo

无法解析从std::async调用std::lower_bound的此实例。例如:

#include <vector>
#include <algorithm>
#include <future>
#include <iostream>

int main() {
  std::vector<int> v = {1,3,4,6,7};
  auto res = std::async(std::launch::async, std::lower_bound, v.begin(), v.end(), 4);
  std::cout << *res.get() << std::endl;
  return 0;
}
#包括
#包括
#包括
#包括
int main(){
向量v={1,3,4,6,7};
auto res=std::async(std::launch::async,std::lower_bound,v.begin(),v.end(),4);

std::cout
std::lower_bound
是一个函数模板,您必须明确指定它的参数才能传递它:

int main() {
  using V = std::vector<int>;
  V v = {1,3,4,6,7};
  auto res = std::async(std::launch::async, std::lower_bound<V::iterator, int>, v.begin(), v.end(), 4);
  std::cout << *res.get() << std::endl;
  return 0;
}
intmain(){
使用V=std::vector;
V={1,3,4,6,7};
auto res=std::async(std::launch::async,std::lower_bound,v.begin(),v.end(),4);

std::cout
std::lower_bound
是一个函数模板,您必须明确指定它的参数才能传递它:

int main() {
  using V = std::vector<int>;
  V v = {1,3,4,6,7};
  auto res = std::async(std::launch::async, std::lower_bound<V::iterator, int>, v.begin(), v.end(), 4);
  std::cout << *res.get() << std::endl;
  return 0;
}
intmain(){
使用V=std::vector;
V={1,3,4,6,7};
auto res=std::async(std::launch::async,std::lower_bound,v.begin(),v.end(),4);

std::cout谢谢。我要补充的是,我添加了一个谓词函数
bool pred(const Type&a,const Type&b)
,并且能够使用
decltype
将其添加到模板参数中,如下所示:
std::lower_bound
谢谢。我要补充的是,我添加了一个谓词函数
bool pred(const Type&a,const Type&b)
并且能够使用
decltype
将其添加到模板参数中,就像这样:
std::lower\u bound