下面的代码是在Ubuntu标准包中提供的类初始化程序列表。在这个迭代器和const_iterator中是相同类型的typedef。我只是想知道为什么我们希望为不同类型的迭代器使用相同的typedef?理想的Iterator应该有typedef _E *迭代器。同一类型的多个typedef
// In the class initializer list:
namespace std
{
/// initializer_list
template<class _E>
class initializer_list
{
public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;
typedef const _E* iterator;
typedef const _E* const_iterator;
P.S:我不能如此,因为这些领域是由满足Container
要求的任何类型的要求我给这个称号
我认为':: reference'应该是'typedef _E&'not'typedef const _E&'。 – 0x499602D2 2013-02-13 17:44:52
您不希望能够修改initializer_list对象中的任何内容,但它需要:: reference才能满足Container概念的要求,因此它们将其标记为const。 – bstamour 2013-02-13 17:48:50