我试图写一个模板getter函数,该节选std::array<T>
也std::vector<T>
有类型的任意内容T
并返回它的一个值
#include <vector>
#include <array>
class Map2d {
private:
unsigned int m_width;
unsigned int m_height;
unsigned int m_size;
public:
Map2d(unsigned int width, unsigned int height)
: m_width(width), m_height(height) {
m_size = m_width * m_height;
}
template <typename T>
struct is_array_or_vector {
enum { value = false };
};
template <typename T, typename A>
struct is_array_or_vector<std::vector<T, A>> {
enum { value = true };
};
template <typename T, std::size_t N>
struct is_array_or_vector<std::array<T, N>> { …
Run Code Online (Sandbox Code Playgroud)