How to mimic template variable declaration

前端 未结 3 1715
滥情空心
滥情空心 2021-01-21 16:51

I have a basic type Item which depends on an integer template parameter N and class Data which holds instances of Item

3条回答
  •  天涯浪人
    2021-01-21 17:15

    How about something with a "type list", like so:

    template  struct Data;
    
    template <> struct Data<> {};
    
    template 
    struct Data : Data
    {
        std::set> item;
        bool contains(const Item & x) const { return item.find(x) != item.end(); }
    };
    

    Usage:

    Data<2, 8, 19> data;   // contains sets of Item<2>, Item<8> and Item<19>
    

提交回复
热议问题