Added IsPointerToType

This commit is contained in:
matthias@arch 2023-01-30 16:05:53 +01:00
parent 6dbd4c7ced
commit 68d04eb43f

View File

@ -1,8 +1,12 @@
#pragma once
#include <concepts>
#include <cstddef>
#include <ranges>
#include <memory>
#include <type_traits>
namespace gz::util {
/// Satisfied when T is in PackTypes
template<typename T, typename... PackTypes>
@ -23,6 +27,19 @@ namespace gz::util {
template<typename T, typename 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>, "");
}