Question

Consider the following code:

#include <tuple>

template <class Result, class Function, class... Types>
Result f(Function func, Types... values)
{
    return std::get<0>(std::make_tuple(func(values)...));
}

template <class... Types>
int g(const Types... values)
{
    return std::get<0>(std::make_tuple(f<Types>([](int n){return n;}, values)...));
}

int main()
{
    return g(42);
}

Under g++ 4.8.1, it produces:

mangling.cpp: In instantiation of ‘g(const Types ...) [with Types = int]::__lambda0’:
mangling.cpp:12:50:   required from ‘struct g(const Types ...) [with Types = int]::__lambda0’
mangling.cpp:12:77:   required from ‘int g(const Types ...) [with Types = int]’
mangling.cpp:17:16:   required from here
mangling.cpp:12:57: sorry, unimplemented: mangling argument_pack_select
     return std::get<0>(std::make_tuple(f<Types>([](int n){return n;}, values)...));
                                                         ^
mangling.cpp: In instantiation of ‘struct g(const Types ...) [with Types = int]::__lambda0’:
mangling.cpp:12:77:   required from ‘int g(const Types ...) [with Types = int]’
mangling.cpp:17:16:   required from here
mangling.cpp:12:57: sorry, unimplemented: mangling argument_pack_select
mangling.cpp:12:57: sorry, unimplemented: mangling argument_pack_select
mangling.cpp:4:8: error: ‘Result f(Function, Types ...) [with Result = int; Function = g(const Types ...) [with Types = {int}]::__lambda0; Types = {int}]’, declared using local type ‘g(const Types ...) [with Types = {int}]::__lambda0’, is used but never defined [-fpermissive]
 Result f(Function func, Types... values)

Is there a workaround to avoid this problem ? Has it been reported and corrected in g++ 4.8.2 or 4.9.0 ?

EDIT: I've just reported the bug here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60130

Was it helpful?

Solution

Do you need a new lambda for each of the expanded parameters? Otherwise this fixes it:

template <class... Types>
int g(const Types... values)
{
    auto func = [](int n){return n;};
    return std::get<0>(std::make_tuple(f<Types>(func, values)...));
}

Live example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top