简体   繁体   中英

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

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); Foo<int, double> foo; do_something(foo.queryCallback); Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM