From 74166cfc16df2d252510eccb4744f301aefcbe64 Mon Sep 17 00:00:00 2001 From: Alfredo Correa Date: Wed, 18 Dec 2024 22:24:02 -0800 Subject: [PATCH] add mull --- include/boost/multi/detail/index_range.hpp | 4 +- .../boost/multi/detail/static_allocator.hpp | 2 +- mull.yml | 5 +- pre-push | 2 +- test/array_ref.cpp | 56 ++++---- test/assignments.cpp | 2 + test/element_access.cpp | 12 +- test/flatted.cpp | 2 + test/index_range.cpp | 102 +++++++------- test/iterator.cpp | 8 +- test/layout.cpp | 2 + test/minimalistic_ptr.cpp | 124 +++++++++--------- test/partitioned.cpp | 24 ++-- 13 files changed, 185 insertions(+), 160 deletions(-) diff --git a/include/boost/multi/detail/index_range.hpp b/include/boost/multi/detail/index_range.hpp index 777094b23..280b5ea08 100644 --- a/include/boost/multi/detail/index_range.hpp +++ b/include/boost/multi/detail/index_range.hpp @@ -209,7 +209,7 @@ class range { } return begin() + (value - front()); } - template [[nodiscard]] constexpr auto contains(Value const& value) const -> bool { return (value >= first_) && (value < last_); } + template [[nodiscard]] constexpr auto contains(Value const& value) const -> bool { return (first_ <= value) && (value < last_); } template [[nodiscard]] constexpr auto count(Value const& value) const -> value_type { return contains(value); } friend constexpr auto intersection(range const& self, range const& other) { @@ -220,7 +220,7 @@ class range { new_first = min(new_first, new_last); return range(new_first, new_last); } - [[nodiscard]] constexpr auto contains(value_type const& value) const { return value >= first_ && value < last_; } + // [[nodiscard]] constexpr auto contains(value_type const& value) const { return (first_ <= value) && (value < last_); } }; template // , class Plus = std::plus<>, class Minus = std::minus<> > diff --git a/include/boost/multi/detail/static_allocator.hpp b/include/boost/multi/detail/static_allocator.hpp index 95062703b..d3c83e129 100644 --- a/include/boost/multi/detail/static_allocator.hpp +++ b/include/boost/multi/detail/static_allocator.hpp @@ -85,7 +85,7 @@ class static_allocator { // NOSONAR(cpp:S4963) this allocator has special seman auto allocate([[maybe_unused]] std::size_t n) -> pointer { assert(n <= N); assert(!dirty_); // do not attempt to resize a vector with static_allocator - dirty_ = true; + // dirty_ = true; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" // buffer_ is aligned as T return reinterpret_cast(&buffer_); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) diff --git a/mull.yml b/mull.yml index be25dee91..c5f82cb98 100644 --- a/mull.yml +++ b/mull.yml @@ -1,7 +1,10 @@ mutators: - cxx_add_assign_to_sub_assign # Replaces += with -= - cxx_add_to_sub # Replaces + with - + - cxx_and_assign_to_or_assign # Replaces &= with |= + - cxx_and_to_or # Replaces & with | + - cxx_assign_const # Replaces `a = b` with `a = 42` - cxx_mul_to_div # Replaces / with * - cxx_lt_to_le # Replaces < with <= timeout: 10000 # in milliseconds -quiet: true # enables additional logging +quiet: true # additional logging? diff --git a/pre-push b/pre-push index ee2d145ef..7dd6039b1 100755 --- a/pre-push +++ b/pre-push @@ -35,6 +35,7 @@ if [[ $(uname -m) != 'arm64' ]]; then export VALGRIND_EXE="valgrind --trace-children=yes --leak-check=full --track-origins=yes --show-leak-kinds=all --suppressions=.valgrind_suppressions --gen-suppressions=all --error-exitcode=1 " (mkdir -p .build.g++ && cd .build.g++ && CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && cmake --build . && ctest --parallel 2 --output-on-failure) || exit 666 + (mkdir -p .build.clang++.mull && cd .build.clang++.mull && CXX=clang++-14 cmake .. -DCMAKE_CXX_FLAGS="-O1 -fpass-plugin=/usr/lib/mull-ir-frontend-14 -g -grecord-command-line -fprofile-instr-generate -fcoverage-mapping" -DCMAKE_TEST_LAUNCHER="mull-runner-14;--strict;--ld-search-path=/usr/lib/x86_64-linux-gnu" && cmake --build . && (ls test/*.x | xargs -n 1 sh -c 'echo $0 && ((mull-runner-14 $0 -test-program=ctest -- -j2 --stop-on-failure) || exit 255)') ) || exit 666 (mkdir -p .build.circle && cd .build.circle && CXX="$HOME/bin/circle" cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_CXX_STANDARD=20 -DDISABLE_MPI=1 -DENABLE_CIRCLE=1 -DCMAKE_THREAD_LIBS_INIT="-lpthread" && cmake --build . && ctest --parallel --output-on-failure --rerun-failed) || exit 666 (mkdir -p .build.clang++-rel && cd .build.clang++-rel && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . && ctest --parallel 2 --output-on-failure) || exit 666 (mkdir -p .build.clang++ && cd .build.clang++ && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Debug && cmake --build . && ctest --parallel 2 --output-on-failure) || exit 666 @@ -46,7 +47,6 @@ export VALGRIND_EXE="valgrind --trace-children=yes --leak-check=full --track-ori (mkdir -p .build.culang && cd .build.culang && cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_CUDA=1 -DCMAKE_CUDA_COMPILER=clang++ -DCMAKE_CUDA_HOST_COMPILER=clang++ -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CUDA_ARCHITECTURES=75 && cmake --build . && ctest --parallel --output-on-failure --rerun-failed) || exit 666 (mkdir -p .build.g++.plus && cd .build.g++.plus && CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 -DBLA_VENDOR=OpenBLAS `#-DCMAKE_CXX_CPPCHECK="cppcheck;--enable=all;--suppress=missingIncludeSystem;--inline-suppr;--std=c++17;--checkers-report=cppcheck.report;--error-exitcode=1"` -DCMAKE_CXX_FLAGS="-D_GLIBCXX_DEBUG=1" -DCMAKE_CXX_FLAGS="-fimplicit-constexpr -fanalyzer -Wno-analyzer-null-dereference -Wno-analyzer-possible-null-dereference -Wno-analyzer-malloc-leak -Wno-analyzer-use-of-uninitialized-value -Wno-analyzer-use-after-free" && cmake --build . && ctest --parallel --output-on-failure -T memcheck) || exit 666 (mkdir -p .build.clang++.plus && cd .build.clang++.plus && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 -DBLA_VENDOR=Generic -DCMAKE_CXX_CLANG_TIDY="clang-tidy" `#-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="iwyu;-Xiwyu;--mapping_file=/home/correaa/boost-multi/.iwyu-test.imp;-Xiwyu;--no_fwd_decls"` && cmake --build . && ASAN_OPTIONS="new_delete_type_mismatch=0" ctest --parallel --output-on-failure) || exit 666 - (mkdir -p .build.clang++.mull && cd .build.clang++.mull && CXX=clang++-14 cmake .. -DCMAKE_CXX_FLAGS="-O1 -fpass-plugin=/usr/lib/mull-ir-frontend-14 -g -grecord-command-line -fprofile-instr-generate -fcoverage-mapping" -DCMAKE_TEST_LAUNCHER="mull-runner-14;--strict;--ld-search-path=/usr/lib/x86_64-linux-gnu" && cmake --build . && (ls test/*.x | xargs -n 1 sh -c 'echo $0 && ((mull-runner-14 $0 -test-program=ctest -- -j2 --stop-on-failure) || exit 255)') ) || exit 666 #(mkdir -p .build.hip && cd .build.hip && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ -DCMAKE_CXX_FLAGS="-DMULTI_USE_HIP" -DCMAKE_HIP_FLAGS="-DMULTI_USE_HIP" -DENABLE_HIP=1 -DCMAKE_HIP_ARCHITECTURES=gfx90a && cmake --build . ) || exit 666 #(mkdir -p .build.g++-.cov && cd .build.g++-.cov && CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="--coverage -lgcov -fno-inline -fno-inline-small-functions -fno-default-inline" -DCMAKE_EXE_LINKER_FLAGS="-lgcov --coverage" && cmake --build . && ASAN_OPTIONS="new_delete_type_mismatch=0" ctest -j 12 --output-on-failure -T Test `# && lcov --directory . --capture --output-file coverage.info && lcov --remove coverage.info '/usr/*' --output-file coverage.info && lcov --list coverage.info && genhtml coverage.info`) || exit 666 diff --git a/test/array_ref.cpp b/test/array_ref.cpp index ee3e119ca..b9b189fa1 100644 --- a/test/array_ref.cpp +++ b/test/array_ref.cpp @@ -164,6 +164,7 @@ BOOST_AUTO_TEST_CASE(array_ref_from_carray) { BOOST_TEST( &mar[1][1] == &arr[1][1] ); mar[1][1] = 90; + BOOST_TEST( mar[1][1] == 90 ); BOOST_TEST( &mar[1][1] == &arr[1][1] ); auto const& a_const = arr; @@ -658,20 +659,21 @@ BOOST_AUTO_TEST_CASE(array_ref_1D) { BOOST_AUTO_TEST_CASE(array_ref_original_tests_carray) { // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) test legacy type - double darr[4][5] = { - {1.0, 2.0}, - {2.0, 3.0}, + int darr[4][5] = { + {1, 2}, + {2, 3}, }; - multi::array_ref ref(&darr[0][0], {4, 5}); - multi::array_ref cref(&darr[0][0], {4, 5}); - multi::array_ref crefc(&darr[0][0], {4, 5}); - multi::array_cref ref2(&darr[0][0], {4, 5}); + multi::array_ref ref(&darr[0][0], {4, 5}); + multi::array_ref cref(&darr[0][0], {4, 5}); + multi::array_ref crefc(&darr[0][0], {4, 5}); + multi::array_cref ref2(&darr[0][0], {4, 5}); BOOST_TEST( &ref[1][2] == &cref [1][2] ); BOOST_TEST( &ref[1][2] == &crefc[1][2] ); BOOST_TEST( &ref[1][2] == & ref2[1][2] ); - ref[1][1] = 2.0; + ref[1][1] = 20; + BOOST_TEST( ref[1][1] == 20 ); #if defined(__clang__) #pragma clang diagnostic push @@ -680,19 +682,20 @@ BOOST_AUTO_TEST_CASE(array_ref_original_tests_carray) { #endif // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) test legacy type - double darr2[4][5] = { - {1.0, 0.0}, - {2.0, 3.0}, + int darr2[4][5] = { + {10, 00}, + {20, 30}, }; - darr2[1][0] = 2.0; + darr2[1][0] = 20; + BOOST_TEST( darr2[1][0] == 20 ); // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) test legacy type auto const& dd = std::as_const(darr2); BOOST_TEST( &(dd[1][2]) == &(darr2[1][2]) ); - BOOST_TEST(( & ref[1].static_array_cast()[1] == &ref[1][1] )); - BOOST_TEST(( &multi::static_array_cast(ref[1])[1] == &ref[1][1] )); + BOOST_TEST(( & ref[1].static_array_cast()[1] == &ref[1][1] )); + BOOST_TEST(( &multi::static_array_cast(ref[1])[1] == &ref[1][1] )); #if defined(__clang__) #pragma clang diagnostic pop @@ -1130,31 +1133,32 @@ BOOST_AUTO_TEST_CASE(diagonal) { } BOOST_AUTO_TEST_CASE(function_passing) { - multi::array arr({3, 3}); - multi::array_ref& arrR = arr; + multi::array arr({3, 3}); + multi::array_ref& arrR = arr; - arrR[0][0] = 2.1; + arrR[0][0] = 21; arr.reextent({5, 5}); - assert(&arrR[0][0] == &arr[0][0]); + BOOST_TEST( arr [0][0] == 21 ); + BOOST_TEST(&arrR[0][0] == &arr[0][0]); } BOOST_AUTO_TEST_CASE(function_passing_2) { - multi::Array arr({3, 3}); - [[maybe_unused]] multi::Array arrR = arr; + multi::Array arr({3, 3}); + [[maybe_unused]] multi::Array arrR = arr; - arrR[0][0] = 5.1; + arrR[0][0] = 51; - [[maybe_unused]] multi::Array arrCR = arr; + [[maybe_unused]] multi::Array arrCR = arr; - assert(&arrCR[0][0] == &arrR[0][0]); + BOOST_TEST(&arrCR[0][0] == &arrR[0][0]); - [[maybe_unused]] multi::Array arrCR2 = arrCR; + [[maybe_unused]] multi::Array arrCR2 = arrCR; arr.reextent({5, 5}); - - assert(&arrR[0][0] == &arr[0][0]); + BOOST_TEST( arrR[0][0] == 51 ); + BOOST_TEST(&arrR[0][0] == &arr[0][0]); } BOOST_AUTO_TEST_CASE(function_passing_3) { diff --git a/test/assignments.cpp b/test/assignments.cpp index 5dc1ce6df..919215fbe 100644 --- a/test/assignments.cpp +++ b/test/assignments.cpp @@ -127,6 +127,8 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro src[0][1][2][3][1] = 99; + BOOST_TEST( src[0][1][2][3][1] == 99 ); + // BOOST_TEST( tmp.unrotated().partitioned(2).transposed().rotated().extensions() == src.extensions() ); // BOOST_TEST( extensions(tmp.unrotated().partitioned(2).transposed().rotated()) == extensions(src) ); } diff --git a/test/element_access.cpp b/test/element_access.cpp index 6f5d05da6..2a7a0f469 100644 --- a/test/element_access.cpp +++ b/test/element_access.cpp @@ -280,14 +280,16 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro } BOOST_AUTO_TEST_CASE(elements_rvalues_assignment) { - std::vector vec = {1.0, 2.0, 3.0}; // NOLINT(fuchsia-default-arguments-calls) + std::vector vec = {10, 20, 30}; // NOLINT(fuchsia-default-arguments-calls) - std::move(vec) = std::vector{3.0, 4.0, 5.0}; // NOLINT(fuchsia-default-arguments-calls) + std::move(vec) = std::vector{30, 40, 50}; // NOLINT(fuchsia-default-arguments-calls) - std::move(vec)[1] = 99.0; // it compiles // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) for testing purposes + std::move(vec)[1] = 990; // it compiles // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) for testing purposes - multi::array arr1 = {1.0, 2.0, 3.0}; - multi::array const arr2 = {1.0, 2.0, 3.0}; + BOOST_TEST( vec[1] == 990 ); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) for testing purposes + + multi::array arr1 = {10, 20, 30}; + multi::array const arr2 = {10, 20, 30}; std::move(arr1) = arr2; // this compiles TODO(correaa) should it? } diff --git a/test/flatted.cpp b/test/flatted.cpp index f357aa2c8..4218d4c8c 100644 --- a/test/flatted.cpp +++ b/test/flatted.cpp @@ -21,6 +21,8 @@ BOOST_AUTO_TEST_CASE(array_flatted_2d) { BOOST_TEST( arr.flatted()[4] == 4 ); arr.flatted()[4] = 44; + + BOOST_TEST( arr.flatted()[4] == 44 ); } BOOST_AUTO_TEST_CASE(array_flatted_3d) { diff --git a/test/index_range.cpp b/test/index_range.cpp index 6d84f2d1e..482df6fbf 100644 --- a/test/index_range.cpp +++ b/test/index_range.cpp @@ -5,83 +5,87 @@ #include +#include + #include // for equal #include // for accumulate #include // for vector namespace multi = boost::multi; -#include #define BOOST_AUTO_TEST_CASE(CasenamE) /**/ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugprone-exception-escape) -BOOST_AUTO_TEST_CASE(multi_range_in_constexpr) { - BOOST_TEST(( multi::extension_t{5, 12}.contains(10) )); + BOOST_AUTO_TEST_CASE(multi_range_in_constexpr) { + BOOST_TEST(( multi::extension_t{5, 12}.contains(10) )); - multi::range const irng{ 5, 12 }; + multi::range const irng{5, 12}; - BOOST_TEST( irng.contains(6) ); - BOOST_TEST( !irng.contains(12) ); + BOOST_TEST( irng.contains( 6) ); + BOOST_TEST( irng.contains(11) ); + BOOST_TEST( !irng.contains(12) ); - BOOST_TEST( * irng.begin() == 5 ); - BOOST_TEST( *(irng.begin() + 1) == 6 ); + BOOST_TEST( * irng.begin() == 5 ); + BOOST_TEST( *(irng.begin() + 1) == 6 ); - BOOST_TEST( irng.first() == 5 ); - BOOST_TEST( irng.last() == 12 ); + BOOST_TEST( irng.first() == 5 ); + BOOST_TEST( irng.last() == 12 ); - BOOST_TEST( irng.front() == 5 ); - BOOST_TEST( irng.back () == 11 ); + BOOST_TEST( irng.front() == 5 ); + BOOST_TEST( irng.back () == 11 ); - std::vector vec = { 5, 6, 7, 8, 9, 10, 11 }; // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls) + std::vector vec = {5, 6, 7, 8, 9, 10, 11}; // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls) - BOOST_TEST(std::equal(irng.begin(), irng.end(), vec.begin(), vec.end())); // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls) + BOOST_TEST(std::equal(irng.begin(), irng.end(), vec.begin(), vec.end())); // testing std::vector of multi:array NOLINT(fuchsia-default-arguments-calls) - auto sum = std::accumulate(irng.begin(), irng.end(), 0); - BOOST_TEST( sum == 5 + 6 + 7 + 8 + 9 + 10 + 11 ); -} + auto sum = std::accumulate(irng.begin(), irng.end(), 0); + BOOST_TEST( sum == 5 + 6 + 7 + 8 + 9 + 10 + 11 ); + } -BOOST_AUTO_TEST_CASE(multi_range2) { - multi::index_extension const iex(10); + BOOST_AUTO_TEST_CASE(multi_range2) { + multi::index_extension const iex(10); - BOOST_TEST( *begin(iex) == 0 ); - BOOST_TEST( size(iex) == 10 ); - BOOST_TEST( iex[0] == 0 ); - BOOST_TEST( iex[1] == 1 ); - BOOST_TEST( iex[9] == 9 ); + BOOST_TEST( *begin(iex) == 0 ); + BOOST_TEST( size(iex) == 10 ); + BOOST_TEST( iex[0] == 0 ); + BOOST_TEST( iex[1] == 1 ); + BOOST_TEST( iex[9] == 9 ); - auto const xbeg = begin(iex); - BOOST_TEST( xbeg[0] == iex[0] ); - BOOST_TEST( xbeg[1] == iex[1] ); + auto const xbeg = begin(iex); + BOOST_TEST( xbeg[0] == iex[0] ); + BOOST_TEST( xbeg[1] == iex[1] ); - BOOST_TEST( std::accumulate( begin(iex), end(iex), static_cast(0U)) == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ); + BOOST_TEST( std::accumulate( begin(iex), end(iex), static_cast(0U)) == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ); - { - multi::iextensions<3> const ies({ - {0, 3}, - {0, 4}, - {0, 5}, - }); + { + multi::iextensions<3> const ies({ + {0, 3}, + {0, 4}, + {0, 5}, + }); - using std::get; + using std::get; - auto const ies0 = get<0>(ies); - auto const ies1 = get<1>(ies); - auto const ies2 = get<2>(ies); + auto const ies0 = get<0>(ies); + auto const ies1 = get<1>(ies); + auto const ies2 = get<2>(ies); - BOOST_TEST( ies0.size() == 3 ); - BOOST_TEST( ies1.size() == 4 ); - BOOST_TEST( ies2.size() == 5 ); + BOOST_TEST( ies0.size() == 3 ); + BOOST_TEST( ies1.size() == 4 ); + BOOST_TEST( ies2.size() == 5 ); - BOOST_TEST( get<0>(ies).size() == 3 ); - BOOST_TEST( get<1>(ies).size() == 4 ); - BOOST_TEST( get<2>(ies).size() == 5 ); + BOOST_TEST( get<0>(ies).size() == 3 ); + BOOST_TEST( get<1>(ies).size() == 4 ); + BOOST_TEST( get<2>(ies).size() == 5 ); #ifndef _MSC_VER // doesn't work in MSVC 14.3 in c++17 mode - auto const [eyes, jays, kays] = ies; - BOOST_TEST( eyes.size() == 3 ); - BOOST_TEST( jays.size() == 4 ); - BOOST_TEST( kays.size() == 5 ); + auto const [eyes, jays, kays] = ies; + BOOST_TEST( eyes.size() == 3 ); + BOOST_TEST( jays.size() == 4 ); + BOOST_TEST( kays.size() == 5 ); #endif + } } + + return boost::report_errors(); } -return boost::report_errors();} diff --git a/test/iterator.cpp b/test/iterator.cpp index 4b6fde4af..3adf38a9e 100644 --- a/test/iterator.cpp +++ b/test/iterator.cpp @@ -124,10 +124,12 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro BOOST_TEST( arrlast + 1 == arrend ); } { - std::vector vec(10000); // std::vector NOLINT(fuchsia-default-arguments-calls) - multi::array_ref arr(vec.data(), {100, 100}); + std::vector vec(10000); // std::vector NOLINT(fuchsia-default-arguments-calls) + multi::array_ref arr(vec.data(), {100, 100}); BOOST_TEST(arr.size() == 100); - begin(arr)[4][3] = 2.0; + begin(arr)[4][3] = 20; + + BOOST_TEST(begin(arr)[4][3] == 20); } } diff --git a/test/layout.cpp b/test/layout.cpp index 3b7cb98cc..f1e7f6754 100644 --- a/test/layout.cpp +++ b/test/layout.cpp @@ -314,6 +314,8 @@ BOOST_AUTO_TEST_CASE(layout_AA) { BOOST_TEST( size(B2) == 4 ); B2[3][3] = 99; + BOOST_TEST( B2[3][3] == 99 ); + multi::array B2copy{B2({0, 2}, {0, 2})}; auto B2copy2 = B2({0, 2}, {0, 2}).decay(); diff --git a/test/minimalistic_ptr.cpp b/test/minimalistic_ptr.cpp index 8bc370b7e..37f8a3ddd 100644 --- a/test/minimalistic_ptr.cpp +++ b/test/minimalistic_ptr.cpp @@ -5,6 +5,8 @@ #include // for array_ptr, array_ref, subarray +#include + #include // for array #include // for iterator_traits #include // for allocator @@ -22,32 +24,31 @@ class ptr : public std::iterator_traits { // minimalistic pointer public: ptr() = default; - constexpr explicit ptr(T* impl) : impl_{ impl } {} - template> // NOLINT(modernize-use-constraints) TODO(correaa) for C++20 - > + constexpr explicit ptr(T* impl) : impl_{impl} {} + template> // NOLINT(modernize-use-constraints) TODO(correaa) for C++20 + > // cppcheck-suppress [noExplicitConstructor,unmatchedSuppression] - ptr(ptr const& other) : impl_{ other.impl_ } {} // NOLINT(google-explicit-constructor, hicpp-explicit-conversions) // NOSONAR(cpp:S1709) + ptr(ptr const& other) : impl_{other.impl_} {} // NOLINT(google-explicit-constructor, hicpp-explicit-conversions) // NOSONAR(cpp:S1709) using typename std::iterator_traits::reference; using typename std::iterator_traits::difference_type; // NOLINTNEXTLINE(fuchsia-overloaded-operator, fuchsia-trailing-return): operator* used because this class simulates a pointer, trailing return helps constexpr auto operator*() const -> reference { return *impl_; } - #if defined(__clang__) - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunknown-warning-option" - #pragma clang diagnostic ignored "-Wunsafe-buffer-usage" - #endif +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunknown-warning-option" +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif // NOLINTNEXTLINE(fuchsia-overloaded-operator, cppcoreguidelines-pro-bounds-pointer-arithmetic): operator+ is overloaded to simulate a pointer - constexpr auto operator+(difference_type n) const { return ptr{ impl_ + n }; } + constexpr auto operator+(difference_type n) const { return ptr{impl_ + n}; } // NOLINTNEXTLINE(fuchsia-overloaded-operator, cppcoreguidelines-pro-bounds-pointer-arithmetic): operator+ is overloaded to simulate a pointer - constexpr auto operator-(difference_type n) const { return ptr{ impl_ - n }; } + constexpr auto operator-(difference_type n) const { return ptr{impl_ - n}; } - #if defined(__clang__) - #pragma clang diagnostic pop - #endif +#if defined(__clang__) +# pragma clang diagnostic pop +#endif // T& operator[](difference_type n) const{return impl_[n];} // optional using default_allocator_type = std::allocator; @@ -61,11 +62,11 @@ class ptr2 : public std::iterator_traits { // minimalistic pointer T* impl_; public: - constexpr explicit ptr2(T* impl) : impl_{ impl } {} - constexpr explicit ptr2(ptr const& other) : impl_{ other.impl_ } {} + constexpr explicit ptr2(T* impl) : impl_{impl} {} + constexpr explicit ptr2(ptr const& other) : impl_{other.impl_} {} template>> // NOLINT(modernize-use-constraints) TODO(correaa) for C++20 // cppcheck-suppress [noExplicitConstructor, unmatchedSuppression] - ptr2(ptr2 const& other) : impl_{ other.impl_ } {} // NOLINT(google-explicit-constructor, hicpp-explicit-conversions) // NOSONAR(cpp:S1709) + ptr2(ptr2 const& other) : impl_{other.impl_} {} // NOLINT(google-explicit-constructor, hicpp-explicit-conversions) // NOSONAR(cpp:S1709) using typename std::iterator_traits::reference; using typename std::iterator_traits::difference_type; @@ -73,20 +74,20 @@ class ptr2 : public std::iterator_traits { // minimalistic pointer // NOLINTNEXTLINE(fuchsia-overloaded-operator, fuchsia-trailing-return): operator* used because this class simulates a pointer, trailing return helps constexpr auto operator*() const -> reference { return *impl_; } - #if defined(__clang__) - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunknown-warning-option" - #pragma clang diagnostic ignored "-Wunsafe-buffer-usage" - #endif +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunknown-warning-option" +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif // NOLINTNEXTLINE(fuchsia-overloaded-operator, cppcoreguidelines-pro-bounds-pointer-arithmetic): operator+ is overloaded to simulate a pointer - constexpr auto operator+(difference_type n) const { return ptr2{ impl_ + n }; } + constexpr auto operator+(difference_type n) const { return ptr2{impl_ + n}; } // NOLINTNEXTLINE(fuchsia-overloaded-operator, cppcoreguidelines-pro-bounds-pointer-arithmetic): operator+ is overloaded to simulate a pointer - constexpr auto operator-(difference_type n) const { return ptr2{ impl_ - n }; } + constexpr auto operator-(difference_type n) const { return ptr2{impl_ - n}; } - #if defined(__clang__) - #pragma clang diagnostic pop - #endif +#if defined(__clang__) +# pragma clang diagnostic pop +#endif // T& operator[](std::ptrdiff_t n) const{return impl_[n];} // optional using default_allocator_type = std::allocator; @@ -94,40 +95,43 @@ class ptr2 : public std::iterator_traits { // minimalistic pointer } // end namespace minimalistic -#include #define BOOST_AUTO_TEST_CASE(CasenamE) /**/ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugprone-exception-escape) -BOOST_AUTO_TEST_CASE(test_minimalistic_ptr) { - std::array buffer{}; - BOOST_TEST( buffer.size() == 400 ); - - using pointer_type = minimalistic::ptr; - multi::array_ptr const CCP(pointer_type{ buffer.data() }, { 20, 20 }); - (*CCP)[2]; // requires operator+ - (*CCP)[1][1]; - (*CCP)[1][1] = 9; - BOOST_TEST( &(*CCP)[1][1] == &buffer[21] ); - - // auto&& CC2 = (*CCP).static_array_cast>(); - auto&& CC2 = CCP->static_array_cast>(); - BOOST_TEST( &CC2[1][1] == &(*CCP)[1][1] ); - - static_assert(std::is_convertible{}, "!"); - - minimalistic::ptr const pd{ nullptr }; - minimalistic::ptr const pcd = pd; - BOOST_TEST( pcd == pd ); - - { - auto&& REF = *CCP; - (void)REF; - static_assert( std::is_same_v> ); - } - { - auto const& REF = *CCP; - (void)REF; - static_assert( std::is_same_v> ); + BOOST_AUTO_TEST_CASE(test_minimalistic_ptr) { + std::array buffer{}; + BOOST_TEST( buffer.size() == 400 ); + + using pointer_type = minimalistic::ptr; + multi::array_ptr const CCP(pointer_type{buffer.data()}, {20, 20}); + (*CCP)[2]; // requires operator+ + (*CCP)[1][1]; + (*CCP)[1][1] = 9; + + BOOST_TEST( (*CCP)[1][1] == 9 ); + BOOST_TEST( &(*CCP)[1][1] == &buffer[21] ); + + // auto&& CC2 = (*CCP).static_array_cast>(); + auto&& CC2 = CCP->static_array_cast>(); + BOOST_TEST( &CC2[1][1] == &(*CCP)[1][1] ); + + static_assert(std::is_convertible{}, "!"); + + minimalistic::ptr const pd{nullptr}; + minimalistic::ptr const pcd = pd; + BOOST_TEST( pcd == pd ); + + { + auto&& REF = *CCP; + (void)REF; + static_assert(std::is_same_v>); + } + { + auto const& REF = *CCP; + (void)REF; + static_assert(std::is_same_v>); + } } + + return boost::report_errors(); } -return boost::report_errors();} diff --git a/test/partitioned.cpp b/test/partitioned.cpp index acdadd16b..20e5af866 100644 --- a/test/partitioned.cpp +++ b/test/partitioned.cpp @@ -104,6 +104,7 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro BOOST_TEST( &A3_ref[1][1][0] == &A2[3][0] ); A3_ref[0][0][0] = 99; + BOOST_TEST( A3_ref[0][0][0] == 99 ); } BOOST_AUTO_TEST_CASE(array_partitioned) { @@ -216,28 +217,27 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro BOOST_TEST( wr.slater_array[2][1] == 521 ); - // what( wr , wr.slater_array, wr.slater_array[2][1] ); wr.slater_array[2][1] = 99990; + BOOST_TEST( wr.slater_array[2][1] == 99990 ); } BOOST_AUTO_TEST_CASE(array_partitioned_add_to_last) { multi::array arr = { { - {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}, - {6.0, 7.0, 8.0, 9.0, 10.0, 11.0}, - {12.0, 13.0, 14.0, 15.0, 16.0, 17.0}, - {18.0, 19.0, 20.0, 21.0, 22.0, 23.0}, - }, + {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}, + {6.0, 7.0, 8.0, 9.0, 10.0, 11.0}, + {12.0, 13.0, 14.0, 15.0, 16.0, 17.0}, + {18.0, 19.0, 20.0, 21.0, 22.0, 23.0}, + }, { - {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}, - {6.0, 7.0, 8.0, 9.0, 10.0, 11.0}, - {12.0, 13.0, 14.0, 15.0, 16.0, 17.0}, - {18.0, 19.0, 20.0, 21.0, 22.0, 23.0}, - }, + {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}, + {6.0, 7.0, 8.0, 9.0, 10.0, 11.0}, + {12.0, 13.0, 14.0, 15.0, 16.0, 17.0}, + {18.0, 19.0, 20.0, 21.0, 22.0, 23.0}, + }, }; auto strides = std::apply([](auto... strds) { return std::array{{strds...}}; }, arr.layout().strides()); - // auto strides = std::apply([](auto... strds) { return std::array{{strds...}}; }, arr.strides()); BOOST_TEST( std::is_sorted(strides.rbegin(), strides.rend()) && arr.num_elements() == arr.nelems() ); // contiguous c-ordering