简体   繁体   中英

Class template overloading, typename and vector of typenames

is there way to overload my class templates with a single typename and vector of typenames?

Like single typename:

template <typename T, ... /*other typedefs same as in second one*/ >
class myClass
{
 myClass(const T & input);
 // ...
}

and vector of typenames (probably contains some syntactical errors):

template <vector<typename T>, ... >
class myClass<vector<T>, ... >
{
 myClass(vector<T> & input);
 // ...
}

Class methods I guess would look like this:

template<typename T, ... >
myClass<T, ... >::myClass(const T & input) {/*do something*/}


template<vector<typename T>, ... >
myClass<vector<T>, ... >::myClass(vector<T> & input) {/*do something*/}

So simply

myClass <string> a; // Should go for first one
myClass <vector<string>> b; // Should go for second one

Is there way how to write this to be syntactically correct?

How about this?

template <typename T, typename...>
class myClass
{
    myClass(const T& input) { /*...*/ }
    // ...
};

template <typename T, typename... R>
class myClass<vector<T>, R...>
{
    myClass(const vector<T>& input) { /*...*/ }
    // ...
};

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