c++ - Two classes that differ only with template parameters -


is possible create 2 template classes same name, differ in number of template parameters? example,

template<typename t> struct tuple {     t item; };  template<typename t1, typename t2> struct tuple {     t1 item1;     t2 item2; }; 

not syntax used, there alternative solutions:

option #1:

(c++03)

template <typename t1, typename t2 = void> struct tuple {     t1 item1;     t2 item2; };  template <typename t1> struct tuple<t1, void> {     t1 item; }; 

demo 1

option #2:

(c++11)

template <typename...> struct tuple;  template <typename t1> struct tuple<t1> {     t1 item; };  template <typename t1, typename t2> struct tuple<t1, t2> {     t1 item1;     t2 item2; }; 

demo 2


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -