0

我有一个基本上实现注册表设计模式的模板类。值通过 Keys 注册并存储在某个容器中:

template <typename Key, typename Value, 
    template <typename...> class Container >
class registry
{
public:
    typedef Key   key_type;
    typedef Value value_type;


    typedef std::pair<key_type, value_type> element_type;
    typedef Container<element_type> container_type;

然后,我可以将它与这样的序列容器一起使用:

registry<const char*,void*, std::list> r1;
registry<const char*,void*, std::vector> r2;

我什至可以将它与别名一起使用:

template <typename T>
using alias_container = std::array<T, 10>;

registry<const char*,void*, alias_container > r4;

但我不知道如何将它与 typedef 一起使用,如下所示:

template <typename T>
class my_container2 
{
    typedef std::array<T,3> type;
};

我基本上想要这样的东西:

registry<const char*,void*, my_container2::type > r5;

非常感谢你的帮助。

4

1 回答 1

2

type取决于提供给 的模板类型my_container2。为了使用它,您需要指定模板参数,例如

registry<const char*,void*, my_container2<some_type>::type > r4;
                                          ^^^^^^^^^ template type here

这与标准类型的迭代器的概念相同。你不能使用container_type::iterator. 你必须使用container_type<some_type>::iterator.

于 2016-02-08T21:54:55.977 回答