When using the new function declarator syntax and decltype, how does one access members? It appears that this is not accessible:
template <typename Func>
struct context_binder
{
public:
context_binder(const Func& func) :
func(func)
{ }
template <typename... TArgs>
auto operator ()(TArgs&&... args) const
-> decltype(this->func(std::forward<TArgs>(args)...))
{
return func(std::forward<TArgs>(args)...);
}
private:
Func func;
};
This yields the compiler error:
scratch.cpp:34:25: error: invalid use of ‘this’ at top level
My compiler is g++ 4.6.2.
My workaround is to declare a static member called self with the same type as the class, which has two problems:
- It will not pick up the CV-qualifiers automatically, like
thiswould. - I have to move the member declarations above the
decltypeusage or it can’t see the member (although that seems more like a compiler bug).
Upgrade to GCC 4.7. Version 4.6 doesn’t support
thiswhere you’re trying to use it.Another question covers some workarounds you might be able to use.