Okay on second thought this might work after all. I put together a simplified version of what I'm trying to do and it compiled fine.
Code:
struct enclosing
{
struct A
{
A(int val)
: var(val)
{
// blah blah blah
}
void operator()(enclosing& ref)
{
// do stuff here with "ref" using "var"
}
int var;
};
template <typename E>
struct B
{
B(const E& val)
: dup(val)
{
// blah blah blah
}
void operator()(E& ref)
{
// do stuff here with "ref" using fields of "dup"
}
E dup;
};
template <typename G>
void work(G fun)
{
// do some things
fun(*this);
// do more stuff here
}
void work(int val)
{
work(A(val));
}
void work()
{
work(B<enclosing>(*this));
}
};
int main()
{
enclosing e;
e.work(123);
e.work();
}
Now I just have to try to fix all the errors in my project to see if it will actually work in the wild.