小编Jen*_*ner的帖子

模板类接受std :: vector <T>或std :: array <T>

我试图写一个模板getter函数,该节选std::array<T>std::vector<T>有类型的任意内容T并返回它的一个值

Map2d.h

#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)

c++ templates sfinae c++11 c++17

2
推荐指数
1
解决办法
681
查看次数

标签 统计

c++ ×1

c++11 ×1

c++17 ×1

sfinae ×1

templates ×1