lundi 23 mars 2015

Function overloading with initialization_list causing ambiguity


I am trying to overload function with initialization_list as parameters with variation to accept map and vector along with an integer. The compiler complains that the function resolution is ambiguous. I am wondering what causes the ambiguity and how to resolve it



#include <memory>
#include <iostream>
#include <map>
#include <initializer_list>

std::shared_ptr<int> foo(const std::initializer_list<std::pair<const std::string, std::shared_ptr<int> > >& il)
{
return std::make_shared<int>();
}
std::shared_ptr<int> foo(const std::initializer_list<std::shared_ptr<int> > & il)
{
return std::make_shared<int>();
}

std::shared_ptr<int> foo(int num)
{
return std::make_shared<int>();
}

int main()
{
foo({ { "a", foo(10) } });
}


Try It OUT >>>


Note



  1. I tried with VS2013 as well as g++ and both of them errors out.

  2. As per @chris the above code compiles in clang

  3. What does the standard say? Or does it actually say anything?




Aucun commentaire:

Enregistrer un commentaire