Alexandre Severino
Alexandre Severino

Reputation: 1613

Tuple which includes a variadic template

I have the following code:

template<typename... A>
void queueQuery(std::string query, std::function<void(A...)> callback = nullptr);

template<typename... A>
std::tuple<std::string, std::function<void(A...)> queryCallback;

std::queue<queryCallback> queryQueue;

I want to make a queue of tuples of strings and functions with variadic number of any given types (pretty complex, I understand).

Is there a way to make this achievable?

I currently get the following error:

/databasedispatcher.h:14: error: data member 'queryCallback' cannot be a member template

Upvotes: 0

Views: 108

Answers (1)

vsoftco
vsoftco

Reputation: 56547

You are defining queryCallback

template<typename... A> 
std::tuple<std::string, std::function<void(A...)> queryCallback;

as a variable template (which is only C++14 compliant). Are you sure that's what you want?

If you want strict C++11 compliance, then wrap your variable into a struct like below:

template<typename... A> 
struct Foo{
    std::tuple<std::string, std::function<void (A...)> > queryCallback;
};

Then use it as do_something(Foo<int, double>().queryCallback); in a temporary, or Foo<int, double> foo; do_something(foo.queryCallback); Hope this helps.

Upvotes: 2

Related Questions