constexpr all the... deques
This commit is contained in:
+29
-29
@@ -76,13 +76,13 @@ class deque {
|
||||
//! @{
|
||||
public:
|
||||
//! Default constructor
|
||||
deque () noexcept :
|
||||
constexpr deque () noexcept :
|
||||
data_{},
|
||||
f{data_.data(), N},
|
||||
r{data_.data()} { }
|
||||
|
||||
//! fill contructor
|
||||
deque(const Data_t& value) noexcept {
|
||||
constexpr deque(const Data_t& value) noexcept {
|
||||
data_.fill(value);
|
||||
f = iterator(data_.data(), N);
|
||||
r = iterator(data_.data(), N);
|
||||
@@ -90,7 +90,7 @@ class deque {
|
||||
|
||||
//! Initializer list contructor
|
||||
template <typename ...It>
|
||||
deque(It&& ...it) noexcept :
|
||||
constexpr deque(It&& ...it) noexcept :
|
||||
data_{{std::forward<It>(it)...}},
|
||||
f(data_.data(), N),
|
||||
r(data_.data(), sizeof...(It)) { }
|
||||
@@ -103,38 +103,38 @@ class deque {
|
||||
//! \name Iterators
|
||||
//! @{
|
||||
public:
|
||||
iterator begin() noexcept { return f+1; }
|
||||
const_iterator begin() const noexcept { return f+1; }
|
||||
const_iterator cbegin() const noexcept { return f+1; }
|
||||
constexpr iterator begin() noexcept { return f+1; }
|
||||
constexpr const_iterator begin() const noexcept { return f+1; }
|
||||
constexpr const_iterator cbegin() const noexcept { return f+1; }
|
||||
|
||||
iterator end() noexcept { return r; }
|
||||
const_iterator end() const noexcept { return r; }
|
||||
const_iterator cend() const noexcept { return r; }
|
||||
constexpr iterator end() noexcept { return r; }
|
||||
constexpr const_iterator end() const noexcept { return r; }
|
||||
constexpr const_iterator cend() const noexcept { return r; }
|
||||
|
||||
reverse_iterator rbegin() noexcept { return r; }
|
||||
const_reverse_iterator rbegin() const noexcept { return r; }
|
||||
const_reverse_iterator crbegin() const noexcept { return r; }
|
||||
constexpr reverse_iterator rbegin() noexcept { return r; }
|
||||
constexpr const_reverse_iterator rbegin() const noexcept { return r; }
|
||||
constexpr const_reverse_iterator crbegin() const noexcept { return r; }
|
||||
|
||||
reverse_iterator rend() noexcept { return f+1; }
|
||||
const_reverse_iterator rend() const noexcept { return f+1; }
|
||||
const_reverse_iterator crend() const noexcept { return f+1; }
|
||||
constexpr reverse_iterator rend() noexcept { return f+1; }
|
||||
constexpr const_reverse_iterator rend() const noexcept { return f+1; }
|
||||
constexpr const_reverse_iterator crend() const noexcept { return f+1; }
|
||||
//! @}
|
||||
|
||||
//! \name Capacity
|
||||
//! @{
|
||||
public:
|
||||
//! \return The size of the deque. The items currently in queue.
|
||||
size_t size() noexcept {
|
||||
constexpr size_t size() noexcept {
|
||||
return full() ? N: (r - f) -1;
|
||||
}
|
||||
//! \return The maximum size of the deque. The items the queue can hold.
|
||||
size_t max_size() noexcept { return N; }
|
||||
constexpr size_t max_size() noexcept { return N; }
|
||||
//! \return The capacity of the deque. The items the queue can hold.
|
||||
size_t capacity() noexcept { return N; }
|
||||
constexpr size_t capacity() noexcept { return N; }
|
||||
//! \return True if the deque is empty
|
||||
bool empty() noexcept { return size() == 0 ? true : false; }
|
||||
constexpr bool empty() noexcept { return size() == 0 ? true : false; }
|
||||
//! \return True if the deque is full
|
||||
bool full() noexcept { return (r == f) ? true : false; }
|
||||
constexpr bool full() noexcept { return (r == f) ? true : false; }
|
||||
//! @}
|
||||
|
||||
//! \name Member access
|
||||
@@ -142,44 +142,44 @@ class deque {
|
||||
public:
|
||||
//! \brief Clears-empty the deque and return it to init state, without
|
||||
//! really deleting the contents.
|
||||
void clear() noexcept {
|
||||
constexpr void clear() noexcept {
|
||||
f = iterator_t(data_.data(), N);
|
||||
r = iterator_t(data_.data());
|
||||
}
|
||||
//! \brief Push an item in the front of the deque
|
||||
//! \param it The item to push
|
||||
void push_front (const Data_t& it) {
|
||||
constexpr void push_front (const Data_t& it) {
|
||||
if (full()) return;
|
||||
*f-- = it;
|
||||
}
|
||||
//! \brief Extract an item from the front of the deque and remove it from the deque
|
||||
//! \param it The item to push
|
||||
Data_t pop_front () {
|
||||
constexpr Data_t pop_front () {
|
||||
if (empty()) return Data_t{};
|
||||
return *++f;
|
||||
}
|
||||
//! \brief Push an item in the back of the deque
|
||||
//! \param it The item to push
|
||||
void push_back (const Data_t& it) {
|
||||
constexpr void push_back (const Data_t& it) {
|
||||
if (full()) return;
|
||||
*r++ = it;
|
||||
}
|
||||
//! \brief Extract an item from the back of the deque and remove it from the deque
|
||||
//! \param it The item to push
|
||||
Data_t pop_back () {
|
||||
constexpr Data_t pop_back () {
|
||||
if (empty()) return Data_t{};
|
||||
return *--r;
|
||||
}
|
||||
|
||||
//! \brief Get a reference to the item in the front of the deque without extracting it.
|
||||
//! \return Reference to the item
|
||||
Data_t& front() noexcept { return *(f+1); }
|
||||
const Data_t& front() const noexcept { return *(f+1); }
|
||||
constexpr Data_t& front() noexcept { return *(f+1); }
|
||||
constexpr const Data_t& front() const noexcept { return *(f+1); }
|
||||
|
||||
//! \brief Get a reference to the item in the front of the deque without extracting it.
|
||||
//! \return Reference to the item
|
||||
Data_t& back() noexcept { return *(r-1); }
|
||||
const Data_t& back() const noexcept { return *(r-1); }
|
||||
constexpr Data_t& back() noexcept { return *(r-1); }
|
||||
constexpr const Data_t& back() const noexcept { return *(r-1); }
|
||||
|
||||
//! @}
|
||||
private:
|
||||
|
||||
@@ -117,11 +117,11 @@ class edeque : public deque<Data_t, N> {
|
||||
//! @{
|
||||
public:
|
||||
//! Default constructor
|
||||
edeque () noexcept :
|
||||
constexpr edeque () noexcept :
|
||||
base_type() { }
|
||||
|
||||
//!
|
||||
edeque (size_match match, size_t size, callable_t&& fn) :
|
||||
constexpr edeque (size_match match, size_t size, callable_t&& fn) :
|
||||
base_type(),
|
||||
mode_{match_mode::SIZE},
|
||||
callback_{std::forward<callable_t>(fn)} {
|
||||
@@ -129,7 +129,7 @@ class edeque : public deque<Data_t, N> {
|
||||
trigger_.tsize.size = size;
|
||||
}
|
||||
|
||||
edeque (data_match match, Data_t value, callable_t&& fn) :
|
||||
constexpr edeque (data_match match, Data_t value, callable_t&& fn) :
|
||||
base_type(),
|
||||
mode_{match_mode::DATA},
|
||||
callback_{std::forward<callable_t>(fn)} {
|
||||
|
||||
@@ -73,14 +73,14 @@ class queue : public deque<Data_t, N> {
|
||||
//! @{
|
||||
public:
|
||||
//! Default constructor
|
||||
queue () noexcept : base_type() { }
|
||||
constexpr queue () noexcept : base_type() { }
|
||||
|
||||
//! fill contructor
|
||||
queue(const Data_t& value) noexcept : base_type(value) { }
|
||||
constexpr queue(const Data_t& value) noexcept : base_type(value) { }
|
||||
|
||||
//! Initializer list contructor
|
||||
template <typename ...It>
|
||||
queue(It&& ...it) noexcept : base_type(std::forward<It>(it)...) { }
|
||||
constexpr queue(It&& ...it) noexcept : base_type(std::forward<It>(it)...) { }
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user