Skip to content

Commit

Permalink
Update more meta functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KredeGC committed Jun 23, 2023
1 parent f5209b3 commit b326dae
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 43 deletions.
10 changes: 4 additions & 6 deletions include/ktl/allocators/cascading.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ namespace ktl
return *this;
}

bool operator==(const cascading& rhs) const
noexcept(noexcept(m_Node == rhs.m_Node))
bool operator==(const cascading& rhs) const noexcept
{
return m_Node == rhs.m_Node;
}

bool operator!=(const cascading& rhs) const
noexcept(noexcept(m_Node != rhs.m_Node))
bool operator!=(const cascading& rhs) const noexcept
{
return m_Node != rhs.m_Node;
}
Expand Down Expand Up @@ -177,7 +175,7 @@ namespace ktl
typename std::enable_if<detail::has_construct_v<Alloc, T*, Args...>, void>::type
construct(T* p, Args&&... args) noexcept(
detail::has_nothrow_owns_v<Alloc> &&
detail::has_noexcept_construct_v<Alloc, T*, Args...>)
detail::has_nothrow_construct_v<Alloc, T*, Args...>)
{
node* next = m_Node;
while (next)
Expand Down Expand Up @@ -206,7 +204,7 @@ namespace ktl
typename std::enable_if<detail::has_destroy_v<Alloc, T*>, void>::type
destroy(T* p) noexcept(
detail::has_nothrow_owns_v<Alloc> &&
detail::has_noexcept_destroy_v<Alloc, T*>)
detail::has_nothrow_destroy_v<Alloc, T*>)
{
node* next = m_Node;
while (next)
Expand Down
12 changes: 6 additions & 6 deletions include/ktl/allocators/fallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace ktl
* @brief Constructor for forwarding a single argument to the primary allocator
*/
template<typename Primary,
typename = std::enable_if_t<detail::can_construct_v<P, Primary>>>
typename = std::enable_if_t<std::is_constructible_v<P, Primary>>>
explicit fallback(Primary&& primary)
noexcept(std::is_nothrow_constructible_v<P, Primary> && std::is_nothrow_default_constructible_v<F>) :
m_Primary(std::forward<Primary>(primary)),
Expand All @@ -46,8 +46,8 @@ namespace ktl
*/
template<typename Primary, typename Fallback,
typename = std::enable_if_t<
detail::can_construct_v<P, Primary> &&
detail::can_construct_v<F, Fallback>>>
std::is_constructible_v<P, Primary> &&
std::is_constructible_v<F, Fallback>>>
explicit fallback(Primary&& primary, Fallback&& fallback)
noexcept(std::is_nothrow_constructible_v<P, Primary> && std::is_nothrow_constructible_v<F, Fallback>) :
m_Primary(std::forward<Primary>(primary)),
Expand All @@ -58,7 +58,7 @@ namespace ktl
*/
template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<P, Args...>>>
std::is_constructible_v<P, Args...>>>
explicit fallback(std::tuple<Args...>&& primary)
noexcept(std::is_nothrow_constructible_v<P, Args...> && std::is_nothrow_default_constructible_v<F>) :
m_Primary(std::make_from_tuple<P>(std::forward<std::tuple<Args...>>(primary))),
Expand All @@ -69,8 +69,8 @@ namespace ktl
*/
template<typename... ArgsP, typename... ArgsF,
typename = std::enable_if_t<
detail::can_construct_v<P, ArgsP...>&&
detail::can_construct_v<F, ArgsF...>>>
std::is_constructible_v<P, ArgsP...>&&
std::is_constructible_v<F, ArgsF...>>>
explicit fallback(std::tuple<ArgsP...>&& primary, std::tuple<ArgsF...>&& fallback)
noexcept(std::is_nothrow_constructible_v<P, ArgsP...> && std::is_nothrow_constructible_v<F, ArgsF...>) :
m_Primary(std::make_from_tuple<P>(std::forward<std::tuple<ArgsP...>>(primary))),
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace ktl
*/
template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<Alloc, Args...>>>
std::is_constructible_v<Alloc, Args...>>>
explicit freelist(Args&&... args)
noexcept(std::is_nothrow_constructible_v<Alloc, Args...>) :
m_Alloc(std::forward<Args>(args)...),
Expand All @@ -75,7 +75,7 @@ namespace ktl
freelist& operator=(const freelist&) = delete;

freelist& operator=(freelist&& rhs)
noexcept(std::is_nothrow_move_constructible<Alloc>)
noexcept(std::is_nothrow_move_constructible_v<Alloc>)
{
release();

Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/overflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace ktl
*/
template<typename T, typename... Args>
void construct(T* p, Args&&... args) noexcept(
(detail::has_construct_v<Alloc, T*, Args...> && detail::has_noexcept_construct_v<Alloc, T*, Args...>) ||
(detail::has_construct_v<Alloc, T*, Args...> && detail::has_nothrow_construct_v<Alloc, T*, Args...>) ||
std::is_nothrow_constructible_v<T, Args...>)
{
m_Constructs++;
Expand All @@ -195,7 +195,7 @@ namespace ktl
*/
template<typename T>
void destroy(T* p) noexcept(
(detail::has_destroy_v<Alloc, T*>&& detail::has_noexcept_destroy_v<Alloc, T*>) ||
(detail::has_destroy_v<Alloc, T*>&& detail::has_nothrow_destroy_v<Alloc, T*>) ||
std::is_nothrow_destructible_v<T>)
{
m_Constructs--;
Expand Down
12 changes: 6 additions & 6 deletions include/ktl/allocators/segragator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace ktl
* @brief Constructor for forwarding a single argument to the primary allocator
*/
template<typename Primary,
typename = std::enable_if_t<detail::can_construct_v<P, Primary>>>
typename = std::enable_if_t<std::is_constructible_v<P, Primary>>>
explicit segragator(Primary&& primary)
noexcept(std::is_nothrow_constructible_v<P, Primary> && std::is_nothrow_default_constructible_v<F>) :
m_Primary(std::forward<Primary>(primary)),
Expand All @@ -43,8 +43,8 @@ namespace ktl
*/
template<typename Primary, typename Fallback,
typename = std::enable_if_t<
detail::can_construct_v<P, Primary> &&
detail::can_construct_v<F, Fallback>>>
std::is_constructible_v<P, Primary> &&
std::is_constructible_v<F, Fallback>>>
explicit segragator(Primary&& primary, Fallback&& fallback)
noexcept(std::is_nothrow_constructible_v<P, Primary> && std::is_nothrow_constructible_v<F, Fallback>) :
m_Primary(std::forward<Primary>(primary)),
Expand All @@ -55,7 +55,7 @@ namespace ktl
*/
template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<P, Args...>>>
std::is_constructible_v<P, Args...>>>
explicit segragator(std::tuple<Args...>&& primary)
noexcept(std::is_nothrow_constructible_v<P, Args...> && std::is_nothrow_default_constructible_v<F>) :
m_Primary(std::make_from_tuple<P>(std::forward<std::tuple<Args...>>(primary))),
Expand All @@ -66,8 +66,8 @@ namespace ktl
*/
template<typename... ArgsP, typename... ArgsF,
typename = std::enable_if_t<
detail::can_construct_v<P, ArgsP...> &&
detail::can_construct_v<F, ArgsF...>>>
std::is_constructible_v<P, ArgsP...> &&
std::is_constructible_v<F, ArgsF...>>>
explicit segragator(std::tuple<ArgsP...>&& primary, std::tuple<ArgsF...>&& fallback)
noexcept(std::is_nothrow_constructible_v<P, ArgsP...> && std::is_nothrow_constructible_v<F, ArgsF...>) :
m_Primary(std::make_from_tuple<P>(std::forward<std::tuple<ArgsP...>>(primary))),
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ktl

template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<Alloc, Args...>>>
std::is_constructible_v<Alloc, Args...>>>
block(Args&&... alloc)
noexcept(std::is_nothrow_constructible_v<Alloc, Args...>) :
Allocator(std::forward<Args>(alloc)...),
Expand All @@ -44,7 +44,7 @@ namespace ktl
*/
template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<Alloc, Args...>>>
std::is_constructible_v<Alloc, Args...>>>
explicit shared(Args&&... alloc)
noexcept(std::is_nothrow_constructible_v<block, Args...>) :
m_Block(detail::aligned_new<block>(detail::ALIGNMENT, std::forward<Args>(alloc)...)) {}
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/threaded.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace ktl

template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<Alloc, Args...>>>
std::is_constructible_v<Alloc, Args...>>>
block(Args&&... alloc)
noexcept(std::is_nothrow_constructible_v<Alloc, Args...>) :
Allocator(std::forward<Args>(alloc)...),
Expand All @@ -48,7 +48,7 @@ namespace ktl
*/
template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<Alloc, Args...>>>
std::is_constructible_v<Alloc, Args...>>>
explicit threaded(Args&&... alloc)
noexcept(std::is_nothrow_constructible_v<block, Args...>) :
m_Block(detail::aligned_new<block>(detail::ALIGNMENT, std::forward<Args>(alloc)...)) {}
Expand Down
2 changes: 1 addition & 1 deletion include/ktl/allocators/type_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ktl
*/
template<typename... Args,
typename = std::enable_if_t<
detail::can_construct_v<Alloc, Args...>>>
std::is_constructible_v<Alloc, Args...>>>
explicit type_allocator(Args&&... alloc)
noexcept(std::is_nothrow_constructible_v<T, Args...>) :
m_Alloc(std::forward<Args>(alloc)...) {}
Expand Down
16 changes: 0 additions & 16 deletions include/ktl/utility/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ namespace ktl::detail
template<typename Alloc>
constexpr bool has_owns_v = has_owns<Alloc, void>::value;

// has Alloc(Args...)
template<typename Void, typename... Types>
struct can_construct : std::false_type {};

template<typename Alloc, typename... Args>
struct can_construct<std::void_t<decltype(Alloc(std::declval<Args>()...))>, Alloc, Args...> : std::true_type {};

template<typename Alloc, typename... Args>
constexpr bool can_construct_v = can_construct<void, Alloc, Args...>::value;



// has allocate(size_t) noexcept
Expand All @@ -98,9 +88,6 @@ namespace ktl::detail
struct has_nothrow_construct<std::enable_if_t<has_construct_v<Alloc, Args...>>, Alloc, Args...>
: std::bool_constant<noexcept(std::declval<Alloc&>().construct(std::declval<Args>()...))> {};

template<typename Alloc, typename... Args>
constexpr bool has_noexcept_construct_v = has_nothrow_construct<void, Alloc, Args...>::value;

template<typename Alloc, typename... Args>
constexpr bool has_nothrow_construct_v = has_nothrow_construct<void, Alloc, Args...>::value;

Expand All @@ -112,9 +99,6 @@ namespace ktl::detail
struct has_nothrow_destroy<Alloc, Ptr, std::enable_if_t<has_destroy_v<Alloc, Ptr>>>
: std::bool_constant<noexcept(std::declval<Alloc&>().destroy(std::declval<Ptr>()))> {};

template<typename Alloc, typename Ptr>
constexpr bool has_noexcept_destroy_v = has_nothrow_destroy<Alloc, Ptr, void>::value;

template<typename Alloc, typename Ptr>
constexpr bool has_nothrow_destroy_v = has_nothrow_destroy<Alloc, Ptr, void>::value;

Expand Down

0 comments on commit b326dae

Please sign in to comment.