Skip to content

Commit

Permalink
Fix #1685 - CTAD for aligned_ptr(T*)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou authored Dec 19, 2023
1 parent 7cfbb8f commit 634a7a1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
3 changes: 3 additions & 0 deletions include/eve/memory/aligned_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ namespace eve
pointer pointer_;
};

template<typename Type>
aligned_ptr(Type* ) -> aligned_ptr<Type>;

//================================================================================================
//! @brief Checks if an aligned_ptr is aligned on a given alignment.
//! @param ptr aligned_ptr to checks
Expand Down
46 changes: 35 additions & 11 deletions test/unit/memory/aligned_ptr.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//==================================================================================================
/**
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
**/
*/
//==================================================================================================
#include "test.hpp"
#include "tts/tts.hpp"
#include <eve/memory/aligned_ptr.hpp>

#include <array>
Expand All @@ -20,15 +21,7 @@ TTS_CASE("aligned_ptr exposes proper traits")
TTS_TYPE_IS( cit_t::value_type, double);
};

TTS_CASE("aligned_ptr constructor from nullptr")
{
eve::aligned_ptr<double> nullptr_constructed_ptr = nullptr;

TTS_EQUAL(nullptr_constructed_ptr.get() , nullptr);
TTS_EQUAL(nullptr_constructed_ptr , nullptr);
};

TTS_CASE("aligned_ptr constructor from more resticted")
TTS_CASE("aligned_ptr conversion rules")
{
TTS_CONSTEXPR_EXPECT( (
std::convertible_to<
Expand Down Expand Up @@ -70,6 +63,37 @@ TTS_CASE("aligned_ptr constructor from more resticted")
>) );
};

TTS_CASE("aligned_ptr constructor from nullptr")
{
eve::aligned_ptr<double> nullptr_constructed_ptr = nullptr;

TTS_EQUAL(nullptr_constructed_ptr.get() , nullptr);
TTS_EQUAL(nullptr_constructed_ptr , nullptr);
};

TTS_CASE("aligned_ptr deduction guide - Default SIMD alignment")
{
constexpr auto size = eve::current_abi_type::bytes;
alignas(size) std::array<std::byte, 2 * size> values;

auto * ptr = &values[ 0 ];
TTS_TYPE_IS(decltype(eve::aligned_ptr(ptr)), eve::aligned_ptr<std::byte>);
TTS_EQUAL(eve::aligned_ptr(ptr).get() , &values[ 0 ]);
TTS_EQUAL(eve::aligned_ptr(ptr) , &values[ 0 ]);
TTS_EQUAL(eve::aligned_ptr(ptr) , eve::as_aligned(ptr));
TTS_NOT_EQUAL(eve::aligned_ptr(ptr) , &values[ 3 ]);
TTS_NOT_EQUAL(eve::aligned_ptr(ptr) , eve::as_aligned(&values[ size ]));

auto const * cptr = &values[ 0 ];
TTS_TYPE_IS(decltype(eve::aligned_ptr(cptr)), eve::aligned_ptr<std::byte const>);
TTS_EQUAL(eve::aligned_ptr(cptr).get() , &values[ 0 ]);
TTS_EQUAL(eve::aligned_ptr(cptr) , &values[ 0 ]);
TTS_EQUAL(eve::aligned_ptr(cptr) , eve::as_aligned(cptr));
TTS_NOT_EQUAL(eve::aligned_ptr(cptr) , &values[ 3 ]);
TTS_NOT_EQUAL(eve::aligned_ptr(cptr) , eve::as_aligned(&values[ size ]));
};


TTS_CASE("aligned_ptr factory functions - Default SIMD alignment")
{
constexpr auto size = eve::current_abi_type::bytes;
Expand Down

0 comments on commit 634a7a1

Please sign in to comment.