c++ - initializer_list and argument-dependent lookup -
i'm trying use std::initializer_list argument in function uses argument-dependent lookup (adl). don't work , don't understand why. following minimal failing example:
#include <initializer_list> #include <iostream> class foo { public: inline friend void bar(std::initializer_list<foo> v) { std::cout << "size = " << v.size() << std::endl; } }; void baz(std::initializer_list<foo> v) { std::cout << "size = " << v.size() << std::endl; } int main(){ foo a; //bar({a,a}); // error: use of undeclared identifier 'bar' baz({a,a}); // works return 0; }
as seen above, equivalent global function works fine. why above not work?
i'm using clang on os x 10.10.
i believe problem subexpression1 { a, }
not have type, , such not have associated types or namespaces in turn means adl not kick in. if have function in global namespace, normal lookup find it, , find { a, }
can match function call initializer std::initializer_list<foo>
.
1 syntax { a, }
called braced-init-list , not expression (or subexpression) in language.
Comments
Post a Comment