Question 1 reverse_iterator and iterator are two iterator types defined in the vector class template. The implementation may be different classes, such as:
template </* ... */>
class vector {
public:
class ReverseIterator {...};
class Iterator {...};
using reverse_iterator = ReverseIterator;
using iterator = Iterator;
};
The opposite direction of iteration is achieved through different operator implementations. If the iterator is internally implemented by a pointer, the operator++的实现可自减该指针,而iterator的operator++ implementation of reverse_iterator can increment the pointer.
Question 2 ostream_iterator<int, char> out_iter(cout, " ");是声明并定义一个变量,且直接初始化(direct initialize)该变量。(cout, " ") is the actual parameter list. The compiler will try to choose a constructor based on this parameter list and "pass" the parameters to the constructor.
According to the standard, cout cannot assign a value to int. Please provide the relevant code. But cout can be converted to bool (after c++11) or void * (before c++11) type. This is because the type of cout inherits an instance of basic_ios, and the basic_ios class template used to instantiate the instance defines the relevant conversion operator. That’s it bool x = std::cout;
What are two numerical values? . reverse_iterator和iteratorIt is an iterator, essentially two class templates Reimplement different details of the function inside the class to achieve different functions, but the external interface is the same
Instantiate an objectout_iter,类型是ostream_iterator<int,char>,传入构造函数的参数是cout和" "
The meaning of the sentence "cout can assign a value to int" is unclear
Question 1
reverse_iterator and iterator are two iterator types defined in the vector class template. The implementation may be different classes, such as:
reverse_iterator
的迭代方向和iterator
相反。即若r1和r2指向同一个元素,r1+1
和r2-1
指向同一个元素(若有效,且它们分别重载了operator+
和operator-
).The opposite direction of iteration is achieved through different operator implementations. If the iterator is internally implemented by a pointer, the
operator++
的实现可自减该指针,而iterator的operator++
implementation of reverse_iterator can increment the pointer.Question 2
ostream_iterator<int, char> out_iter(cout, " ");
是声明并定义一个变量,且直接初始化(direct initialize)该变量。(cout, " ")
is the actual parameter list. The compiler will try to choose a constructor based on this parameter list and "pass" the parameters to the constructor.According to the standard, cout cannot assign a value to int. Please provide the relevant code. But cout can be converted to bool (after c++11) or void * (before c++11) type. This is because the type of cout inherits an instance of basic_ios, and the basic_ios class template used to instantiate the instance defines the relevant conversion operator. That’s it
bool x = std::cout;
What are two numerical values? .
reverse_iterator
和iterator
It is an iterator, essentially two class templatesReimplement different details of the function inside the class to achieve different functions, but the external interface is the same
Instantiate an object
out_iter
,类型是ostream_iterator<int,char>
,传入构造函数的参数是cout
和" "
The meaning of the sentence "cout can assign a value to int" is unclear