My Project
Public Types | Public Member Functions | Related Functions | List of all members
bsl::contiguous_iterator< T > Class Template Referencefinal

Provides a contiguous iterator as defined by the C++ specification, with the follwing differences: More...

#include <contiguous_iterator.hpp>

Public Types

using value_type = T
 alias for: T
 
using size_type = bsl::uintmax
 alias for: bsl::uintmax
 
using difference_type = bsl::uintmax
 alias for: bsl::uintmax
 
using reference_type = T &
 alias for: T &
 
using const_reference_type = T const &
 alias for: T const &
 
using pointer_type = T *
 alias for: T *
 
using const_pointer_type = T const *
 alias for: T const *
 

Public Member Functions

constexpr contiguous_iterator (pointer_type const ptr, size_type const count, size_type const i=0U) noexcept
 Creates a contiguous iterator given a ptr to an array and the total number of elements in the array. Note that you should not use this directly but instead, should use the container's begin() function. More...
 
constexpr pointer_type data () noexcept
 Returns a pointer to the array being iterated. More...
 
constexpr const_pointer_type data () const noexcept
 Returns a pointer to the array being iterated. More...
 
constexpr size_type size () const noexcept
 Returns the number of elements in the array being iterated. More...
 
constexpr size_type index () const noexcept
 Returns the iterator's current index. If the iterator is at the end, this function returns size(). More...
 
constexpr bool empty () const noexcept
 Returns nullptr == data() More...
 
constexpr bool is_end () const noexcept
 Returns index() == size() More...
 
constexpr pointer_type get_if () noexcept
 Returns a pointer to the instance of T stored at the iterator's current index. If the index is out of bounds, or the iterator is invalid, this function returns a nullptr. More...
 
constexpr contiguous_iteratoroperator++ () noexcept
 Increments the iterator. More...
 
constexpr contiguous_iteratoroperator-- () noexcept
 Decrements the iterator. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
constexpr bool operator== (contiguous_iterator< T > const &lhs, contiguous_iterator< T > const &rhs) noexcept
 Returns true if the provided contiguous iterators point to the same array and the same index. More...
 
template<typename T >
constexpr bool operator!= (contiguous_iterator< T > const &lhs, contiguous_iterator< T > const &rhs) noexcept
 Returns true if the provided contiguous iterators do not point to the same array or the same index. More...
 
template<typename T >
constexpr bool operator< (contiguous_iterator< T > const &lhs, contiguous_iterator< T > const &rhs) noexcept
 Returns lhs.index() < rhs.index() More...
 
template<typename T >
constexpr bool operator<= (contiguous_iterator< T > const &lhs, contiguous_iterator< T > const &rhs) noexcept
 Returns lhs.index() <= rhs.index() More...
 
template<typename T >
constexpr bool operator> (contiguous_iterator< T > const &lhs, contiguous_iterator< T > const &rhs) noexcept
 Returns lhs.index() > rhs.index() More...
 
template<typename T >
constexpr bool operator>= (contiguous_iterator< T > const &lhs, contiguous_iterator< T > const &rhs) noexcept
 Returns lhs.index() >= rhs.index() More...
 

Detailed Description

template<typename T>
class bsl::contiguous_iterator< T >

Provides a contiguous iterator as defined by the C++ specification, with the follwing differences:

Template Parameters
Tthe type of element being iterated.

Constructor & Destructor Documentation

◆ contiguous_iterator()

template<typename T>
constexpr bsl::contiguous_iterator< T >::contiguous_iterator ( pointer_type const  ptr,
size_type const  count,
size_type const  i = 0U 
)
inlinenoexcept

Creates a contiguous iterator given a ptr to an array and the total number of elements in the array. Note that you should not use this directly but instead, should use the container's begin() function.

Parameters
ptra pointer to the array being iterated
countthe number of elements in the array being iterated
ithe initial index of the iterator

Member Function Documentation

◆ data() [1/2]

template<typename T>
constexpr pointer_type bsl::contiguous_iterator< T >::data ( )
inlinenoexcept

Returns a pointer to the array being iterated.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_data() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter{str.begin()};
if (str.data() == iter.data()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a pointer to the array being iterated

◆ data() [2/2]

template<typename T>
constexpr const_pointer_type bsl::contiguous_iterator< T >::data ( ) const
inlinenoexcept

Returns a pointer to the array being iterated.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_data() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter{str.begin()};
if (str.data() == iter.data()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a pointer to the array being iterated

◆ size()

template<typename T>
constexpr size_type bsl::contiguous_iterator< T >::size ( ) const
inlinenoexcept

Returns the number of elements in the array being iterated.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_size() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter{str.begin()};
if (str.size() == iter.size()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns the number of elements in the array being iterated

◆ index()

template<typename T>
constexpr size_type bsl::contiguous_iterator< T >::index ( ) const
inlinenoexcept

Returns the iterator's current index. If the iterator is at the end, this function returns size().

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_index() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter{str.begin()};
if (0U == iter.index()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns the iterator's current index

◆ empty()

template<typename T>
constexpr bool bsl::contiguous_iterator< T >::empty ( ) const
inlinenoexcept

Returns nullptr == data()

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_empty() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter{str.begin()};
if (!iter.empty()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns nullptr == data()

◆ is_end()

template<typename T>
constexpr bool bsl::contiguous_iterator< T >::is_end ( ) const
inlinenoexcept

Returns index() == size()

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_is_end() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter{str.end()};
if (iter.is_end()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns index() == size()

◆ get_if()

template<typename T>
constexpr pointer_type bsl::contiguous_iterator< T >::get_if ( )
inlinenoexcept

Returns a pointer to the instance of T stored at the iterator's current index. If the index is out of bounds, or the iterator is invalid, this function returns a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_get_if() noexcept
{
constexpr bsl::string_view str{"Hello"};
bsl::string_view::iterator_type iter{str.begin()};
if (auto const *const ptr = iter.get_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}

SUPPRESSION: PRQA 4024 - false positive

  • We suppress this because A9-3-1 states that pointer we should not provide a non-const reference or pointer to private member function, unless the class mimics a smart pointer or a containter. This class mimics a container.
Returns
Returns a pointer to the instance of T stored at the iterator's current index. If the index is out of bounds, or the iterator is invalid, this function returns a nullptr.

◆ operator++()

template<typename T>
constexpr contiguous_iterator& bsl::contiguous_iterator< T >::operator++ ( )
inlinenoexcept

Increments the iterator.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_increment() noexcept
{
constexpr bsl::string_view str{"Hello"};
bsl::string_view::iterator_type iter{str.begin()};
++iter;
if (auto const *const ptr = iter.get_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
returns *this

◆ operator--()

template<typename T>
constexpr contiguous_iterator& bsl::contiguous_iterator< T >::operator-- ( )
inlinenoexcept

Decrements the iterator.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_decrement() noexcept
{
constexpr bsl::string_view str{"Hello"};
bsl::string_view::iterator_type iter{str.end()};
--iter;
if (auto const *const ptr = iter.get_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
returns *this

Friends And Related Function Documentation

◆ operator==()

template<typename T >
constexpr bool operator== ( contiguous_iterator< T > const &  lhs,
contiguous_iterator< T > const &  rhs 
)
related

Returns true if the provided contiguous iterators point to the same array and the same index.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_equals() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter1{str.begin()};
constexpr bsl::string_view::iterator_type iter2{str.begin()};
constexpr bsl::string_view::iterator_type iter3{str.end()};
if (iter1 == iter2) {
bsl::print() << "success\n";
}
if (iter1 != iter3) {
bsl::print() << "success\n";
}
if (iter1 < iter3) {
bsl::print() << "success\n";
}
if (iter1 <= iter2) {
bsl::print() << "success\n";
}
if (iter3 > iter1) {
bsl::print() << "success\n";
}
if (iter3 >= iter1) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being iterated.
Parameters
lhsthe left hand side of the operation
rhsthe rhs hand side of the operation
Returns
Returns true if the provided contiguous iterators point to the same array and the same index.

◆ operator!=()

template<typename T >
constexpr bool operator!= ( contiguous_iterator< T > const &  lhs,
contiguous_iterator< T > const &  rhs 
)
related

Returns true if the provided contiguous iterators do not point to the same array or the same index.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_not_equals() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter1{str.begin()};
constexpr bsl::string_view::iterator_type iter2{str.begin()};
constexpr bsl::string_view::iterator_type iter3{str.end()};
if (iter1 == iter2) {
bsl::print() << "success\n";
}
if (iter1 != iter3) {
bsl::print() << "success\n";
}
if (iter1 < iter3) {
bsl::print() << "success\n";
}
if (iter1 <= iter2) {
bsl::print() << "success\n";
}
if (iter3 > iter1) {
bsl::print() << "success\n";
}
if (iter3 >= iter1) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being iterated.
Parameters
lhsthe left hand side of the operation
rhsthe rhs hand side of the operation
Returns
Returns true if the provided contiguous iterators do not point to the same array or the same index.

◆ operator<()

template<typename T >
constexpr bool operator< ( contiguous_iterator< T > const &  lhs,
contiguous_iterator< T > const &  rhs 
)
related

Returns lhs.index() < rhs.index()

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_lt() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter1{str.begin()};
constexpr bsl::string_view::iterator_type iter2{str.begin()};
constexpr bsl::string_view::iterator_type iter3{str.end()};
if (iter1 == iter2) {
bsl::print() << "success\n";
}
if (iter1 != iter3) {
bsl::print() << "success\n";
}
if (iter1 < iter3) {
bsl::print() << "success\n";
}
if (iter1 <= iter2) {
bsl::print() << "success\n";
}
if (iter3 > iter1) {
bsl::print() << "success\n";
}
if (iter3 >= iter1) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being iterated.
Parameters
lhsthe left hand side of the operation
rhsthe rhs hand side of the operation
Returns
Returns lhs.index() < rhs.index()

◆ operator<=()

template<typename T >
constexpr bool operator<= ( contiguous_iterator< T > const &  lhs,
contiguous_iterator< T > const &  rhs 
)
related

Returns lhs.index() <= rhs.index()

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_lt_equals() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter1{str.begin()};
constexpr bsl::string_view::iterator_type iter2{str.begin()};
constexpr bsl::string_view::iterator_type iter3{str.end()};
if (iter1 == iter2) {
bsl::print() << "success\n";
}
if (iter1 != iter3) {
bsl::print() << "success\n";
}
if (iter1 < iter3) {
bsl::print() << "success\n";
}
if (iter1 <= iter2) {
bsl::print() << "success\n";
}
if (iter3 > iter1) {
bsl::print() << "success\n";
}
if (iter3 >= iter1) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being iterated.
Parameters
lhsthe left hand side of the operation
rhsthe rhs hand side of the operation
Returns
Returns lhs.index() <= rhs.index()

◆ operator>()

template<typename T >
constexpr bool operator> ( contiguous_iterator< T > const &  lhs,
contiguous_iterator< T > const &  rhs 
)
related

Returns lhs.index() > rhs.index()

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_gt() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter1{str.begin()};
constexpr bsl::string_view::iterator_type iter2{str.begin()};
constexpr bsl::string_view::iterator_type iter3{str.end()};
if (iter1 == iter2) {
bsl::print() << "success\n";
}
if (iter1 != iter3) {
bsl::print() << "success\n";
}
if (iter1 < iter3) {
bsl::print() << "success\n";
}
if (iter1 <= iter2) {
bsl::print() << "success\n";
}
if (iter3 > iter1) {
bsl::print() << "success\n";
}
if (iter3 >= iter1) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being iterated.
Parameters
lhsthe left hand side of the operation
rhsthe rhs hand side of the operation
Returns
Returns lhs.index() > rhs.index()

◆ operator>=()

template<typename T >
constexpr bool operator>= ( contiguous_iterator< T > const &  lhs,
contiguous_iterator< T > const &  rhs 
)
related

Returns lhs.index() >= rhs.index()

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_contiguous_iterator_gt_equals() noexcept
{
constexpr bsl::string_view str{"Hello"};
constexpr bsl::string_view::iterator_type iter1{str.begin()};
constexpr bsl::string_view::iterator_type iter2{str.begin()};
constexpr bsl::string_view::iterator_type iter3{str.end()};
if (iter1 == iter2) {
bsl::print() << "success\n";
}
if (iter1 != iter3) {
bsl::print() << "success\n";
}
if (iter1 < iter3) {
bsl::print() << "success\n";
}
if (iter1 <= iter2) {
bsl::print() << "success\n";
}
if (iter3 > iter1) {
bsl::print() << "success\n";
}
if (iter3 >= iter1) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of element being iterated.
Parameters
lhsthe left hand side of the operation
rhsthe rhs hand side of the operation
Returns
Returns lhs.index() >= rhs.index()

The documentation for this class was generated from the following file: