based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit a0d7367e41db6fcb4dbc602c1023bea128d5b54a
parent 639b106015bc740d6eec37a5316aac64ca28556f
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Thu, 26 Jun 2025 11:18:25 +0200

Fix issues with Array

Diffstat:
M .clang-format | + -
M .clang-tidy | +++ -
M include/based/container/array.hpp | +++++++++++++++++++++++++++ ---------
M test/CMakeLists.txt | +
A test/source/container/array_test.cpp | +++++++++++++++

5 files changed, 47 insertions(+), 11 deletions(-)


diff --git a/ .clang-format b/ .clang-format

@@ -6,7 +6,7 @@ AlignAfterOpenBracket: BlockIndent

AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: DontAlign
AlignTrailingComments: false

diff --git a/ .clang-tidy b/ .clang-tidy

@@ -153,7 +153,7 @@ CheckOptions:

- key: 'readability-identifier-naming.TypeAliasCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.TypeAliasIgnoredRegexp'
value: '(size_type|value_type|difference_type|pointer|const_pointer|reference|const_reference|iterator|const_iterator|reverse_iterator|const_reverse_iterator)'
value: '(size_type|value_type|difference_type|pointer|const_pointer|reference|const_reference|iterator|const_iterator|reverse_iterator|const_reverse_iterator|allocator_type|propagate_on_container_move_assignment|iterator_category)'
- key: 'readability-identifier-naming.TypedefCase'
value: 'lower_case'
- key: 'readability-identifier-naming.TypeTemplateParameterCase'

@@ -162,6 +162,8 @@ CheckOptions:

value: 'lower_case'
- key: 'readability-identifier-naming.ValueTemplateParameterCase'
value: 'lower_case'
- key: 'readability-identifier-naming.ValueTemplateParameterIgnoredRegexp'
value: '(N)'
- key: 'readability-identifier-naming.VariableCase'
value: 'lower_case'
- key: 'readability-identifier-naming.VirtualMethodCase'

diff --git a/ include/based/container/array.hpp b/ include/based/container/array.hpp

@@ -66,10 +66,10 @@ public:

[[nodiscard]] constexpr const_reverse_iterator crend() const;

// Capacity
[[nodiscard]] constexpr size_type size() const { return N; }
[[nodiscard]] constexpr size_type max_size() const { return N; }
[[nodiscard]] constexpr size_type size() const;
[[nodiscard]] constexpr size_type max_size() const;

[[nodiscard]] constexpr bool empty() const { return size() == 0; }
[[nodiscard]] constexpr bool empty() const;

// Operations
constexpr void fill(const value_type& value);

@@ -93,7 +93,7 @@ auto constexpr operator<=>(const ARRAY& lhs, const ARRAY& rhs)

TEMPLATE
inline auto constexpr ARRAY::fill(const ARRAY::value_type& value) -> void
{
std::fill_n(begin(), size(), value);
std::fill_n(begin(), size().value, value);
}

TEMPLATE

@@ -123,13 +123,15 @@ inline auto constexpr ARRAY::begin() const -> ARRAY::const_iterator

TEMPLATE
inline auto constexpr ARRAY::end() -> ARRAY::iterator
{
return iterator(addressof(m_instance[N]));
// NOLINTNEXTLINE(*array-bounds*)
return iterator(addressof(m_instance[N.value]));
}

TEMPLATE
inline auto constexpr ARRAY::end() const -> ARRAY::const_iterator
{
return const_iterator(addressof(m_instance[N]));
// NOLINTNEXTLINE(*array-bounds*)
return const_iterator(addressof(m_instance[N.value]));
}

TEMPLATE

@@ -165,7 +167,8 @@ inline auto constexpr ARRAY::cbegin() const -> ARRAY::const_iterator

TEMPLATE
inline auto constexpr ARRAY::cend() const -> ARRAY::const_iterator
{
return const_iterator(addressof(m_instance[N]));
// NOLINTNEXTLINE(*array-bounds*)
return const_iterator(addressof(m_instance[N.value]));
}

TEMPLATE

@@ -208,13 +211,13 @@ inline auto constexpr ARRAY::front() const -> ARRAY::const_reference

TEMPLATE
inline auto constexpr ARRAY::back() -> ARRAY::reference
{
return N ? *(end() - 1) : *end();
return N != size_type(0) ? *(end() - 1) : *end();
}

TEMPLATE
inline auto constexpr ARRAY::back() const -> ARRAY::const_reference
{
return N ? *(end() - 1) : *end();
return N != size_type(0) ? *(end() - 1) : *end();
}

TEMPLATE

@@ -229,6 +232,21 @@ inline auto constexpr ARRAY::data() const -> ARRAY::const_pointer

return addressof(m_instance[0]);
}

TEMPLATE inline auto constexpr ARRAY::size() const -> ARRAY::size_type
{
return N;
}

TEMPLATE inline auto constexpr ARRAY::max_size() const -> ARRAY::size_type
{
return N;
}

TEMPLATE inline auto constexpr ARRAY::empty() const -> bool
{
return size() == size_type(0);
}

#undef TEMPLATE
#undef ARRAY

diff --git a/ test/CMakeLists.txt b/ test/CMakeLists.txt

@@ -89,6 +89,7 @@ add_test(character mapper_test)

## ----- Container -----

add_test(container list_test)
add_test(container array_test)

# ---- End-of-file commands ----

diff --git a/ test/source/container/array_test.cpp b/ test/source/container/array_test.cpp

@@ -0,0 +1,15 @@

#include "based/container/array.hpp"

#include <catch2/catch_test_macros.hpp>

#include "based/integral/literals.hpp"

using namespace based::literals; // NOLINT(*namespace*)

template class based::Array<based::U16, based::U8, 0_u8>;
template class based::Array<based::U16, based::U8, 1_u8>;

TEST_CASE("Array", "[container/Array]")
{
REQUIRE(true);
}