about const iterators
Sep 18, 2017 at 1:21am UTC
can anyone tell me what the difference btw the iterator
const_reverse_iterator rbegin()
and const_reverse_iterator crbegin() ?
How should i write BOOST unit test case for each scenario?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
in a header file i have the following definition for
iterators:
// iterators
iterator begin() noexcept { return iterator(beg_); }
iterator end() noexcept { return iterator(end_); }
const_iterator cbegin() const noexcept { return const_iterator(beg_); }
const_iterator cend() const noexcept { return const_iterator(end_); }
const_iterator begin() const noexcept { return cbegin(); }
const_iterator end() const noexcept { return cend(); }
reverse_iterator rbegin() noexcept { return reverse_iterator(end_); }
reverse_iterator rend() noexcept { return reverse_iterator(beg_); }
const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end_); }
const_reverse_iterator crend() const noexcept { return const_reverse_iterator(beg_); }
const_reverse_iterator rbegin() const noexcept { return cbegin(); }
const_reverse_iterator rend() const noexcept { return cend(); }
Sep 18, 2017 at 1:58am UTC
const_reverse_iterator crbegin() const returns a const iterator even if the sequence container is non-const.
This is a bug:
1 2
const_reverse_iterator rbegin() const noexcept { return cbegin (); }
const_reverse_iterator rend() const noexcept { return cend (); }
Once it is corrected,
1 2
const_reverse_iterator rbegin() const noexcept { return crbegin (); }
const_reverse_iterator rend() const noexcept { return crend (); }
we would need to write test cases only for one of these pairs:
either a.
cbegin() and
cend() or b.
begin() and
end() on a const sequence container.
If it is a class room exercise, and the code compiles cleanly, this bug may have been deliberately introduced, to test if you can catch it with a test case. You need to test that reverse iterators iterate in the reverse direction.
Last edited on Sep 18, 2017 at 2:28am UTC
Topic archived. No new replies allowed.