1

I'm using this code to create multiple functions wrappers using variadic templates:

// Compile with g++ -std=c++0x $(pkg-config sigc++-2.0 --cflags --libs) test.cpp -o test
#include <iostream>
#include <type_traits>
#include <sigc++/sigc++.h>

template <typename R, typename G, typename... Ts>
class FuncWrapper
{
public:
  FuncWrapper(G object, std::string const& name, sigc::slot<R, Ts...> function) {};
};

int main()
{
  FuncWrapper<void, int, int, bool, char> tst(0, "test", [] (int a, bool b, char c) {});

  return EXIT_SUCCESS;
}

This code correctly compiles with clang++, but not with g++ due to the known issue:

test.cpp:9:73: sorry, unimplemented: cannot expand ‘Ts ...’ into a fixed-length argument list

I know that gcc-4.7 should handle this correctly, but I can't upgrade for now... So I'd like to have a workaround to make Ts... to unpack correctly. I've tested what suggested here in questions like this one, but they don't seem to solve the issue here.

Community
  • 1
  • 1
Treviño
  • 2,999
  • 3
  • 28
  • 23

1 Answers1

5

You can workaround the bug with:

template<template <typename...> class T, typename... Args>
struct Join
{ typedef T<Args...> type; };

then replace sigc::slot<R, Ts...> with typename Join<sigc::slot, R, Ts...>::type

(Thanks to Chris Jefferson's suggestion on the GCC bug report)

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521