C++11 variadic template templates

Hi there,

Is there anyway to have a template template class with multi variadic templates
something like this:

1
2
3
4
5
template<template<typename...> class Node, typename... NodeT,
	  template<typename...> class Link, typename... LinkT>
class Network
{
};


Thanks in advance for your answers.

Happy Coding!
how do you plan to use a variadic template class? Give an example?
I have two template classes Node and Link:

1
2
3
4
5
6
7
8
9
template<typename ... Args>
class Node
{
}
template<typename ... Args>
class Link
{
}


I
I want a template class Network that is composed of Nodes and Links.

1
2
3
4
5
6
7
template<template<typename...> class NODE, typename... NODET,
	  template<typename...> class LINK, typename... LINKT>
class Network
{
vector<NODE<NODET...> > nodes;
vector<LINK<LINKT...> > links;
};


For example, consider these Node and Link classes:
1
2
Link<std::string> l = Link<std::string> ();
Node<int,int> n = Node <int,int> ();


I want a to be able to pass to the Network class the typenames of Node (int,int) and typename of Link (std::string) and create the following Network class:
Network<Node, int, int, Link, std::string>;
Last edited on
1
2
3
4
5
6
7
8
9
10
template <typename N, typename L>
class Network {
    std::vector<N> nodes;
    std::vector<L> links;
};

int main() {
    Network<Node<int, int>, Link<std::string>> net;
    return 0;
}


http://coliru.stacked-crooked.com/a/de39b1a1c4bcd7ed
credit: http://stackoverflow.com/a/17524437/2089675
Last edited on
Thanks a lot for your answer!

Your code allows any typenames for Network. For example, one may instantiate a Network <std::vector<int>, std::vector<int>>().

This is what I finally did. This way, I can only instantiate network with Node and Link:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
template<typename ... Args>
class Node
{
}
template<typename ... Args>
class Link
{
}
template <typename...> class Network;
template< typename... NodeT,
			 typename... LinkT>
class Network<Node<NodeT...>, Link<LinkT...>>
{
}

int main () 
{
Network<Node<int,int>,Link<std::string>> n = Network<Node<int,int>,Link<std::string>> ();
return 0
}
Last edited on
Topic archived. No new replies allowed.