Initializer_list and argument-dependent search

I am trying to use std :: initializer_list as an argument in a function that uses argument-dependent search (ADL). But I do not work, and I do not understand why. The following is a minimal 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 you can see above, the equivalent global function works fine. Why does the above not work?

I am using clang for OS X 10.10.

+4
source share
2 answers

, , 1{ a, a } , , , , , ADL in. , , , { a, a } std::initializer_list<Foo>.

1 { a, a } braced-init-list ( ) .

+8

bar({a,a}), , bar (::) . Foo{a,a}, , Foo, Foo .

+2

All Articles