Skip to content
Snippets Groups Projects

Added extended AllTrueBitSetVector class

Merged Praetorius, Simon requested to merge feature/alltruebitsetvector into master
All threads resolved!
Files
3
#pragma once
#include <cstddef>
#include <iterator>
namespace AMDiS
{
/// \brief Vector-like container of bools returning always true
/// \brief Vector-like container of bools returning always true.
/**
* Model of an infinite range of bools of value `true` with vector-like element
* access by `operator[]`.
**/
class AllTrueBitSetVector
{
public:
using value_type = bool;
struct const_iterator
{
constexpr const_iterator(bool sentinel = false) noexcept : sentinel_(sentinel) {}
using value_type = bool;
using reference = bool;
using difference_type = std::ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
constexpr bool operator*() const noexcept { return true; }
constexpr const_iterator& operator++() noexcept { return *this; }
constexpr const_iterator operator++(int) noexcept { return *this; }
/// Comparison of the iterator is always true if both are sentinel or both are const_iterator
friend constexpr bool operator==(const_iterator a, const_iterator b) noexcept
{
return a.sentinel_ == b.sentinel_;
}
bool sentinel_ = false;
/// Comparison of the iterator is always true
constexpr bool operator==(const_iterator) const noexcept { return true; }
constexpr bool operator!=(const_iterator) const noexcept { return false; }
};
/// Constexpr default constructor
constexpr AllTrueBitSetVector() noexcept = default;
public: // element access
/// Converting to true
constexpr operator bool() const noexcept
{
return true;
}
/// Access any element of the container returning always true.
/// Access to any element of the container returns always true.
template <class Index>
constexpr const AllTrueBitSetVector& operator[](Index const& /*index*/) const noexcept
constexpr AllTrueBitSetVector const& at(Index const& /*index*/) const noexcept
{
return *this;
}
/// Access to any element of the container returns always true.
template <class Index>
constexpr AllTrueBitSetVector const& operator[](Index const& /*index*/) const noexcept
{
return *this;
}
/// Access the front element of the infinite range
constexpr AllTrueBitSetVector const& front() const noexcept
{
return *this;
}
public: // iterators
/// Return iterator that always redirects to a bool true.
constexpr const_iterator begin() const noexcept { return const_iterator{false}; }
constexpr const_iterator end() const noexcept { return const_iterator{true}; }
constexpr const_iterator begin() const noexcept { return const_iterator{}; }
/// Return iterator that always redirects to a bool true.
constexpr const_iterator cbegin() const noexcept { return const_iterator{false}; }
constexpr const_iterator cend() const noexcept { return const_iterator{true}; }
constexpr const_iterator cbegin() const noexcept { return const_iterator{}; }
public: // capacity and modifier
/// Resize does nothing
template <class Size>
constexpr void resize(Size const& /*size*/) const noexcept { /* do nothing */ }
constexpr void resize(Size const& /*size*/) const noexcept
{
/* do nothing */
}
/// The container is always non-empty
constexpr bool empty() const noexcept
{
return false;
}
};
} // end namespace AMDiS
Loading