See this simple example,
constexpr auto f = [](const auto& foo){
foo.fun2();
};
struct Foo{
friend decltype(f);
void fun1() const{
f(*this);
}
private:
void fun2() const{}
};
int main(){
Foo foo{};
foo.fun1();
}
the friend declaration does not seem to work. gcc complains that the fun2 is private even though f is given the access.
this results in compiler error
<source>: In instantiation of '<lambda(const auto:1&)> [with auto:1 = Foo]':
<source>:9:16: required from here
<source>:2:13: error: 'void Foo::fun2() const' is private within this context
2 | foo.fun2();
| ~~~~~~~~^~
<source>:13:10: note: declared private here
13 | void fun2() const{}