|
libpqxx
3.1.1
|
Let's say you have a result object. For example, your program may have done:
Now how do you access the data inside r?
The simplest way is array indexing. A result acts as an array of tuples, and a tuple acts as an array of fields.
But results and rows also define const_iterator types:
They also have const_reverse_iterator types, which iterate backwards from rbegin() to rend() exclusive.
All these iterator types provide one extra bit of convenience that you won't normally find in C++ iterators: referential transparency. You don't need to dereference them to get to the row or field they refer to. That is, instead of row->end() you can also choose to say row.end(). Similarly, you may prefer field.c_str() over field->c_str().
This becomes really helpful with the array-indexing operator. With regular C++ iterators you would need ugly expressions like (*row)[0] or row->operator[](0). With the iterator types defined by the result and tuple classes you can simply say row[0].