diff --git a/include/fennec/containers/array.h b/include/fennec/containers/array.h index 4ab83e8..61eb02c 100644 --- a/include/fennec/containers/array.h +++ b/include/fennec/containers/array.h @@ -60,8 +60,12 @@ namespace fennec /// \tparam ValueT value type /// \tparam ElemV number of elements template -struct array -{ +struct array { + +// Definitions ========================================================================================================= +public: + using value_t = ValueT; ///< Alias for `ValueT` + // Public Members ====================================================================================================== /// \name Public Members @@ -69,7 +73,7 @@ struct array /// /// \brief backing c-style array handle - ValueT elements[ElemV]; + value_t data[ElemV]; /// @} @@ -101,9 +105,9 @@ struct array /// /// \copydetails array::operator[](size_t) const - constexpr ValueT& operator[](size_t i) { + constexpr value_t& operator[](size_t i) { assertd(i < ElemV, "Array Out of Bounds"); - return elements[i]; + return data[i]; } /// @@ -117,9 +121,37 @@ struct array /// /// \par Space-Complexity /// Constant - constexpr const ValueT& operator[](size_t i) const { + constexpr const value_t& operator[](size_t i) const { assertd(i < ElemV, "Array Out of Bounds"); - return elements[i]; + return data[i]; + } + + /// + /// \brief Access the first element + /// \returns A reference to the element at `elements[0]` + constexpr value_t& front() { + return data[0]; + } + + /// + /// \brief Const Access the first element + /// \returns A const-qualified reference to the element at `elements[0]` + constexpr const value_t& front() const { + return data[0]; + } + + /// + /// \brief Access the first element + /// \returns A reference to the element at `elements[ElemV - 1]` + constexpr value_t& back() { + return data[ElemV - 1]; + } + + /// + /// \brief Const Access the first element + /// \returns A const-qualified reference to the element at `elements[ElemV - 1]` + constexpr const value_t& back() const { + return data[ElemV - 1]; } /// @} @@ -154,15 +186,15 @@ struct array /// /// \brief C++ Iterator Specification `begin()` /// \returns A pointer to the first element of the array - constexpr ValueT* begin() { - return elements; + constexpr value_t* begin() { + return data; } /// /// \brief C++ Iterator Specification `end()` /// \returns A pointer to one after the end of the array - constexpr ValueT* end() { - return elements + ElemV; + constexpr value_t* end() { + return data + ElemV; } @@ -170,15 +202,15 @@ struct array /// /// \brief Const C++ Iterator Specification `begin()` /// \returns A const-qualified pointer to the first element of the array - constexpr const ValueT* begin() const { - return elements; + constexpr const value_t* begin() const { + return data; } /// /// \brief Const C++ Iterator Specification `end()` /// \returns A const-qualified pointer to one after the end of the array - constexpr const ValueT* end() const { - return elements + ElemV; + constexpr const value_t* end() const { + return data + ElemV; } /// @} diff --git a/include/fennec/containers/deque.h b/include/fennec/containers/deque.h index daca335..79ff1fa 100644 --- a/include/fennec/containers/deque.h +++ b/include/fennec/containers/deque.h @@ -102,6 +102,16 @@ public: , _size(0) { } + /// + /// \brief Alloc Constructor, initializes an empty deque with the specified allocator + /// \param alloc the allocator to copy + deque(const alloc_t& alloc) + : _alloc(alloc) + , _first(nullptr) + , _last(nullptr) + , _size(0) { + } + /// /// \brief Copy Constructor /// \param deque the deque to copy diff --git a/include/fennec/containers/detail/_tuple.h b/include/fennec/containers/detail/_tuple.h index b569279..0380dac 100644 --- a/include/fennec/containers/detail/_tuple.h +++ b/include/fennec/containers/detail/_tuple.h @@ -29,9 +29,12 @@ template struct _tuple_leaf { template - _tuple_leaf(ArgT&& arg) : value(fennec::forward(arg)) {} + constexpr _tuple_leaf(ArgT&& arg) : value(fennec::forward(arg)) {} - ~_tuple_leaf() = default; + constexpr ~_tuple_leaf() = default; + + constexpr _tuple_leaf& operator=(const _tuple_leaf&) = default; + constexpr _tuple_leaf& operator=(_tuple_leaf&&) noexcept = default; T value; }; @@ -43,9 +46,14 @@ template struct _tuple, TypesT...> : _tuple_leaf... { template - _tuple(ArgsT&&... args) : _tuple_leaf(fennec::forward(args))... {} + constexpr _tuple(ArgsT&&... args) + : _tuple_leaf(fennec::forward(args))... { + } - ~_tuple() = default; + constexpr _tuple& operator=(const _tuple&) = default; + constexpr _tuple& operator=(_tuple&&) noexcept = default; + + constexpr ~_tuple() = default; }; } diff --git a/include/fennec/containers/list.h b/include/fennec/containers/list.h index ba52c10..c67697f 100644 --- a/include/fennec/containers/list.h +++ b/include/fennec/containers/list.h @@ -72,16 +72,15 @@ private: struct node; public: - ///< Alias for the allocator type, rebound to list nodes + /// \brief Alias for the allocator type, rebound to list nodes using alloc_t = typename allocator_traits::template rebind; - using value_t = TypeT; - using elem_t = node; + using value_t = TypeT; ///< Alias for the value type - static constexpr size_t npos = -1; + static constexpr size_t npos = -1; ///< Constant representing a non-existant position - class iterator; - class const_iterator; + class iterator; ///< Iterator type for forward iteration over the list + class const_iterator; ///< Iterator type for forward iteration over a constant list // Constructors & Destructor =========================================================================================== diff --git a/include/fennec/containers/map.h b/include/fennec/containers/map.h index 181d789..374ad84 100644 --- a/include/fennec/containers/map.h +++ b/include/fennec/containers/map.h @@ -81,15 +81,15 @@ struct map { // Definitions ========================================================================================================= public: - struct key_hash; - struct node_equals; - using key_t = KeyT; - using value_t = ValueT; - using elem_t = pair; - using alloc_t = typename allocator_traits::template rebind; - using hash_t = Hash; - using set_t = set; - using iterator = set_t::iterator; + struct key_hash; ///< Hash for node keys + struct key_equals; ///< Comparison for node keys + using key_t = KeyT; ///< The key type + using value_t = ValueT; ///< The value type + using elem_t = pair; ///< then node type + using alloc_t = typename allocator_traits::template rebind; ///< Rebinds the allocator type to nodes + using hash_t = Hash; ///< The hash type + using set_t = set; ///< The underlying set + using iterator = set_t::iterator; ///< Iterator type // We only want to hash the key struct key_hash : hash_t { @@ -99,7 +99,7 @@ public: }; // We only want to compare the keys - struct node_equals : equality { + struct key_equals : equality { constexpr bool operator()(const elem_t& a, const elem_t& b) const { return equality::operator()(a.first, b.first); } @@ -248,7 +248,7 @@ public: } /// - /// \brief Clears the set, destructing all elements + /// \brief Clears the map destructing all elements void clear() { _set.clear(); } diff --git a/include/fennec/containers/multiset.h b/include/fennec/containers/multiset.h index 1d82f57..ed79ca3 100644 --- a/include/fennec/containers/multiset.h +++ b/include/fennec/containers/multiset.h @@ -550,7 +550,7 @@ private: template constexpr void _insert(ArgsT&&...args) { - if (_size == 0 or static_cast(_size) / capacity() >= _load) { // expand when full + if (_size == 0 or static_cast(_size) / capacity() >= _load) { // expand when full _expand(); } @@ -578,7 +578,7 @@ private: equal_t _equal; size_t _size; size_t _sumpsl; - double _load; + float _load; }; } diff --git a/include/fennec/containers/object_pool.h b/include/fennec/containers/object_pool.h index d187a7e..f248259 100644 --- a/include/fennec/containers/object_pool.h +++ b/include/fennec/containers/object_pool.h @@ -159,20 +159,25 @@ public: /// - /// \brief Move Insertion, inserts a copy of `x` into the pool - /// \param x the object to copy + /// \brief Emplacement, constructs a new object using `args...` + /// \param args The arguments to construct the new object with /// \returns An integer corresponding to the id of the node template constexpr size_t emplace(ArgsT&&...args) { return this->_insert(fennec::forward(args)...); } + /// + /// \brief Erase an object from the pool + /// \param i The id of the object constexpr void erase(size_t i) { _table[i] = nullopt; _freed.push_back(i); --_size; } + /// @} + private: dynarray _table; list _freed; diff --git a/include/fennec/containers/optional.h b/include/fennec/containers/optional.h index a24546a..40759cb 100644 --- a/include/fennec/containers/optional.h +++ b/include/fennec/containers/optional.h @@ -141,7 +141,7 @@ public: /// /// \brief Implicit Boolean Check, returns `true` when there is a value contained - constexpr operator bool() const { + constexpr explicit operator bool() const { return _set; } diff --git a/include/fennec/containers/set.h b/include/fennec/containers/set.h index ba4582d..7fa1aec 100644 --- a/include/fennec/containers/set.h +++ b/include/fennec/containers/set.h @@ -455,7 +455,7 @@ private: template constexpr iterator _insert(ArgsT&&...args) { - if (_size == 0 or double(_size) / capacity() >= _load) { // expand when full + if (_size == 0 or static_cast(_size) / capacity() >= _load) { // expand when full _expand(); } @@ -484,7 +484,7 @@ private: equal_t _equal; size_t _size; size_t _sumpsl; - double _load; + float _load; }; }