Q:

Best way to avoid code huge duplication when deducing return type using decltype

I have this very convoluted example here:
auto someClassFactory(const Arg1& arg1, const Arg2& arg2, const Arg3)
{
    auto lambda = [arg1](const SomeArg& a) {
        // 10 or so line lambda...
        // ...
        // ...
    };

    return SomeClass<decltype(lambda)>{arg2, arg3, lambda};
}

I have a bunch of similar factory functions for constructing SomeClass with various different functors.
Using the above technique with no trailing return type works just nicely compiling with -std=c++1y on gcc 4.8, but I'm not keen on using c++1y features just yet, nor am I keen on using an enormous, code duplicating decltype for trailing return type.
What other options are there for deducing the lambda for use in the return type?
I've considered using std::function, but would prefer to avoid using that in this case.

A:

Replace lambda with an explicit functor.
Alternatively, create a make_class function that perfect forwards the lambda and deduces its type into a some_class constructor, relying on RVO to elide any copies or use {direct construction} to explicitly construct the return value, and maybe a RETURNS macro:
#define RETURNS(x) ->decltype(x) { return (x); }

… which does not work now that I think about it, as we get a lambda in a non evaluated context.

