Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::reverse_iterator, fkyaml::basic_node::const_reverse_iterator¶
using reverse_iterator = detail::reverse_iterator<iterator>;
using const_reverse_iterator = detail::reverse_iterator<const_iterator>;
The types of non-const/const reverse iterators for basic_node
containers.
They satisfies LegacyBidirectionalIterator and are commonly used for sequence and mapping container nodes.
Member Types¶
reverse_iterator¶
Type | Definition |
---|---|
iterator_type |
basic_node::iterator |
iterator_category |
std::bidirectional_iterator_tag |
value_type |
basic_node |
difference_type |
std::ptrdiff_t |
pointer |
basic_node* |
reference |
basic_node& |
const_reverse_iterator¶
Type | Definition |
---|---|
iterator_type |
basic_node::const_iterator |
iterator_category |
std::bidirectional_iterator_tag |
value_type |
basic_node |
difference_type |
std::ptrdiff_t |
pointer |
const basic_node* |
reference |
const basic_node& |
Member Functions¶
Name | Description |
---|---|
key | Returns const reference to a key node of the current key-value pair.fkyaml::exception is thrown if an iterator points to a sequence element. |
value | Returns reference to a sequence element if an element points to a sequence element, or a mapping value otherwise. |
Examples¶
Example
#include <iomanip>
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
// create a container node.
fkyaml::node sequence_node = {1, 2, 3};
// get an iterator to the first sequence element.
fkyaml::node::reverse_iterator it = sequence_node.rbegin();
fkyaml::node::const_reverse_iterator end_it = sequence_node.crend();
// print all the elements.
// note `reverse_iterator` and `const_reverse_iterator` are comparable.
for (; it != end_it; ++it) {
std::cout << *it << std::endl;
}
it = sequence_node.rbegin();
try {
// key() cannot be called on an iterator pointing to a sequence element.
std::cout << it.key() << std::endl;
}
catch (const fkyaml::exception& e) {
std::cout << e.what() << std::endl;
}
return 0;
}
output: