I would like to partially specialise a class template for std::vector containing fundamental types.
My approach looks like this, but does not compile
#include <type_traits>
#include <vector>
#include <string>
#include <iostream>
template <typename T, bool bar = false>
struct foo {
static void show()
{
std::cout << "T" << std::endl;
}
};
template <typename T>
struct foo<typename std::enable_if<std::is_fundamental<T>::value, std::vector<T>>::type, false> {
static void show()
{
std::cout << "std::vector<fundamental type>" << std::endl;
}
};
template <typename T>
struct foo<std::vector<T>, false> {
static void show()
{
std::cout << "std::vector<T>" << std::endl;
}
};
int main()
{
foo<int>::show();
foo<std::vector<int>>::show();
foo<std::vector<std::string>>::show();
}
How can I make it work?
Aucun commentaire:
Enregistrer un commentaire