提升 - 类模板队列

BOOST - Class template queue

本文关键字:队列 提升      更新时间:2023-10-16

我试图在 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);
.......
};

我试图一步一步地理解模板 - 所以

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

对我来说意味着当提供类型 T、A0、A1 和 A2 时将创建模板,例如

queue<int, char, myclass, char>

其中myclass是一个用户定义的类 - 我希望我的理解是正确的。但我无法理解的是以下部分——

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 &);

它似乎是另一个模板中的模板 - 但是我们如何提供类型来实例化

template<typename T, typename... Options>

template<typename U>

有没有办法像类一样理解模板构造,以了解模板方法的参数和返回类型是什么?

template<typename U>是一个queue构造函数模板。它的参数是从调用它时传递的参数推断出来的。

struct implementation_defined是一个常规的嵌套类,实际上并不是模板本身。它看起来像一个文档问题,因为它实际上被定义为

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