Parma Polyhedra Library requirements
C++ read-only bidirectional iterator adapters

C++ read-only bidirectional iterator adapters

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-001595

iterator_to_const<Container> shall store a Container::iterator; const_iterator_to_const<Container> shall store a Container::const_iterator. Both wrappers shall expose the five iterator traits of Container::const_iterator. Admitted containers shall provide bidirectional mutable and constant iterators, with constant-iterator reference and pointer types providing ordinary const element references and pointers. Each selected underlying iterator operation shall be well-formed and satisfy its own lifetime, range and synchronization conditions.

Default construction shall value-initialize the underlying position. Copying and assignment shall preserve the borrowed position without copying an element or taking ownership of the sequence. Assignment shall return a reference to its target. Conversion from a mutable wrapper to its constant counterpart shall preserve the position and element identity; the reverse conversion shall not be provided. Construction from an underlying position shall remain restricted to the declared friends. Destruction shall destroy the stored iterator without destroying the borrowed container or elements. Underlying exceptions shall propagate with the underlying operation's state guarantees and normal completed-subobject cleanup.

Position validity and invalidation shall follow the underlying container. Singular positions shall be used only for operations admitted for the underlying singular iterator; element access and movement shall require valid range positions. The adapters shall impose no numerical initialization prerequisite of their own. Element operations shall retain their prerequisites.

Container traversal needs copyable borrowed positions while disjunct values remain protected by the container interface.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check aliases and C++20 bidirectional iterator concepts for the list-backed powerset instantiation. Exercise default/copy/assignment, self-assignment and conversion; reject reverse conversion at compile time. Inspect generic underlying-exception propagation and completed-subobject cleanup. Check that destroying wrappers preserves the collection and erasing an unrelated list element preserves retained positions.

src/iterator_to_const_defs.hh; src/iterator_to_const_inlines.hh; tests/readonlyiteratorsspec1.cc; src/Powerset_defs.hh.

CPP
Internal

Public header: <ppl.hh>; implementation names in Parma_Polyhedra_Library. Member excerpts apply to the indicated types.

template <typename Container> class iterator_to_const;
template <typename Container> class const_iterator_to_const;
// Both classes expose iterator_category, value_type, difference_type,
// pointer and reference from the container's constant iterator traits.
iterator_to_const();
iterator_to_const(const iterator_to_const&);
iterator_to_const& operator=(const iterator_to_const&);
const_iterator_to_const();
const_iterator_to_const(const const_iterator_to_const&);
const_iterator_to_const& operator=(const const_iterator_to_const&) = default;
const_iterator_to_const(const iterator_to_const<Container>&);
SW_SPEC
2
PPL-SPEC-001596
PPL-SPEC-001596
Read-only iterator element identity and const access

At a valid dereferenceable position, operator* shall return the underlying element as the declared constant reference, and operator-> shall return a pointer to that same element as the declared constant pointer. Both mutable-container and constant-container wrappers shall prevent direct mutation through their exposed reference and pointer types. Access shall preserve the stored position and the identity of the borrowed element, without copying it. The valid-use conditions of 🔗 1. Read-only iterator types, borrowed positions and value operations shall apply. An end or singular iterator shall not be dereferenced.

Read-only element access allows the container to maintain its representation invariants through controlled element replacement.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check reference/pointer constness at compile time and compare referent addresses from dereference, arrow, independent copies and const conversion. Check every position against an independently constructed value; verify that wrapper destruction preserves element addresses and collection contents.

src/iterator_to_const_defs.hh; src/iterator_to_const_inlines.hh; tests/readonlyiteratorsspec1.cc; src/Powerset_defs.hh.

CPP
Internal

Public header: <ppl.hh>; implementation names in Parma_Polyhedra_Library. Member excerpts apply to the indicated types.

// Members of both read-only iterator adapter classes:
reference operator*() const;
pointer operator->() const;
SW_SPEC
3
PPL-SPEC-001597
PPL-SPEC-001597
Read-only iterator traversal and interoperable equality

Prefix increment and decrement shall move the stored position by one underlying step and return a reference to the same wrapper. Postfix forms shall make the same movement and return a wrapper holding the preceding position. Copies shall thereafter move independently. Forward and reverse traversal shall follow the underlying sequence order without modifying its elements.

Equality shall compare the underlying positions; inequality shall be its Boolean complement. Mutable and constant wrappers of the same container type shall support both operand orders, with comparison through the corresponding constant position. Comparisons shall require positions in an underlying comparison domain, including the same sequence when required by that iterator. Movement shall remain within the underlying bidirectional range: increment of its end and decrement of its begin shall not be admitted. Decrement of end shall be admitted for a nonempty range. The conditions of 🔗 1. Read-only iterator types, borrowed positions and value operations shall apply.

Generic collection algorithms need ordinary bidirectional traversal and consistent equality across mutable and constant collection views.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check prefix return identities, postfix old values, independent copied positions and both directions of each equality/inequality outcome. Traverse three distinguishable elements forward and backward, use end decrement and standard distance/reverse adapters, and check preserved sequence contents.

src/iterator_to_const_defs.hh; src/iterator_to_const_inlines.hh; tests/readonlyiteratorsspec1.cc; src/Powerset_defs.hh.

CPP
Internal

Public header: <ppl.hh>; implementation names in Parma_Polyhedra_Library. Member excerpts apply to the indicated types.

// Members of iterator_to_const<Container>:
iterator_to_const& operator++();
iterator_to_const operator++(int);
iterator_to_const& operator--();
iterator_to_const operator--(int);
bool operator==(const iterator_to_const&) const;
bool operator!=(const iterator_to_const&) const;
// Members of const_iterator_to_const<Container>:
const_iterator_to_const& operator++();
const_iterator_to_const operator++(int);
const_iterator_to_const& operator--();
const_iterator_to_const operator--(int);
bool operator==(const const_iterator_to_const&) const;
bool operator!=(const const_iterator_to_const&) const;
template <typename Container>
bool operator==(const iterator_to_const<Container>&,
                const const_iterator_to_const<Container>&);
template <typename Container>
bool operator!=(const iterator_to_const<Container>&,
                const const_iterator_to_const<Container>&);