简体   繁体   English

BOOST-类模板队列

[英]BOOST - Class template queue

I was trying to read on Boost Class template queue and found the below content of class template: 我试图阅读Boost类模板队列 ,发现以下类模板的内容:

template<typename T, typename A0, typename A1, typename A2> 
class queue {
    public:
  // member classes/structs/unions
  template<typename T, typename... Options> 
  struct implementation_defined {
    // types
    typedef node_allocator allocator;
    typedef std::size_t    size_type;
  };
  // construct/copy/destruct
  queue(void);
  template<typename U> 
    explicit queue(typename node_allocator::template rebind< U >::other const &);
  explicit queue(allocator const &);
  explicit queue(size_type);
  template<typename U> 
    queue(size_type, 
          typename node_allocator::template rebind< U >::other const &);
  ~queue(void);
.......
};

I was trying to understand the template step by step - so 我试图逐步了解模板-所以

template<typename T, typename A0, typename A1, typename A2> 

meant to me that the template would be created when provided types T, A0, A1 and A2 like 对我来说意味着将在提供T,A0,A1和A2类型时创建模板

queue<int, char, myclass, char>

where myclass is a user defined class - I hope I am correct in my understanding. myclass是用户定义的类-我希望我理解正确。 But what I could not understand is the below section - 但是我不明白的是下面的部分-

  template<typename T, typename... Options> 
  struct implementation_defined {
    // types
    typedef node_allocator allocator;
    typedef std::size_t    size_type;
  };
  // construct/copy/destruct
  queue(void);
  template<typename U> 
    explicit queue(typename node_allocator::template rebind< U >::other const &);

It seems a template inside another template - but then how do we provide types to instantiate 似乎在另一个模板中有一个模板-但是我们如何提供实例化的类型

template<typename T, typename... Options>

and

template<typename U>

Is there a way to understand template construction like classes to understand what a templates methods are its arguments and return type? 有没有办法像类一样理解模板构造,以了解其参数和返回类型是什么模板方法?

template<typename U> is a queue constructor function template. template<typename U>queue构造函数模板。 Its parameter is deduced from argument you are passing when invoking it. 它的参数是从调用时传递的参数推导出来的。

struct implementation_defined is a regular nested class, that is not actually a template itself. struct implementation_defined是一个常规的嵌套类,实际上不是模板本身。 It looks like a documentation issue because it is actually defined as 它看起来像一个文档问题,因为它实际上定义为

struct implementation_defined
{
    typedef node_allocator allocator;
    typedef std::size_t size_type;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM