Compiler misunderstanding about functions with tuple arguments

I am using the Apple LLVM 4.2 compiler to compile this code in C ++. I overloaded a member function with various combinations of tuples, and I believe that I find one of them correctly, but the compiler finds ambiguity. In essence, I am trying to call method (1) below, but the compiler finds method (2) also acceptable / compatible. Why is this? I have C ++ 11 flags enabled.

enum class Enum1 { ... } enum class Enum2 { ... } enum class Enum3 { ... } enum class Enum4 { ... } void myMethod() { Enum1 e1; Enum2 e2; Enum3 e3; doSomething({e1,e2,e3}); // should pick (1), yet compiler finds (2) compatible also!? } inline void doSomething(const tuple<Enum1,Enum2,Enum3>& p) { // (1) ... } inline void doSomething(const tuple<Enum1,Enum2,Enum3,Enum4>& p) { // (2) ... } 
+4
source share
1 answer

Are you sure that the compiler considers acceptable, and does not say that no one is acceptable and does not list the candidates? std::tuple an argument constructor for the explicit element, and therefore is not suitable when it comes to copy-initializing a parameter from a copied initializer. In other words, none of the functions should be selected.

You need to explicitly build a tuple in the argument.

+2
source

Source: https://habr.com/ru/post/1500555/


All Articles