Added IsPointerToType
This commit is contained in:
parent
6dbd4c7ced
commit
68d04eb43f
@ -1,8 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
#include <cstddef>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace gz::util {
|
namespace gz::util {
|
||||||
/// Satisfied when T is in PackTypes
|
/// Satisfied when T is in PackTypes
|
||||||
template<typename T, typename... PackTypes>
|
template<typename T, typename... PackTypes>
|
||||||
@ -23,6 +27,19 @@ namespace gz::util {
|
|||||||
template<typename T, typename ValueType>
|
template<typename T, typename ValueType>
|
||||||
concept ContiguousRange = std::ranges::contiguous_range<T> and std::same_as<std::ranges::range_value_t<T>, ValueType>;
|
concept ContiguousRange = std::ranges::contiguous_range<T> and std::same_as<std::ranges::range_value_t<T>, ValueType>;
|
||||||
|
|
||||||
|
/// ObjectType accessible via *t and convertible to bool
|
||||||
|
template<typename T, typename ObjectType>
|
||||||
|
concept IsPointerToType = requires (T t/*, std::ptrdiff_t idx*/) {
|
||||||
|
/* { t.operator*() } -> std::same_as<std::add_lvalue_reference_t<ObjectType>>; */
|
||||||
|
/* { t.operator->() } -> std::same_as<std::add_pointer_t<ObjectType>>; */
|
||||||
|
/* { t.operator[](idx) } -> std::same_as<std::add_lvalue_reference_t<ObjectType>>; */
|
||||||
|
{ *t } -> std::same_as<std::add_lvalue_reference_t<ObjectType>>;
|
||||||
|
/* { t-> } -> std::same_as<std::add_lvalue_reference_t<ObjectType>>; */
|
||||||
|
{ static_cast<bool>(t) };
|
||||||
|
};
|
||||||
|
static_assert(IsPointerToType<std::shared_ptr<int>, int>, "");
|
||||||
|
static_assert(IsPointerToType<int*, int>, "");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user