kokkos-execution 0.0.1
Loading...
Searching...
No Matches
properties.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_IMPL_PROPERTIES_HPP
2#define KOKKOS_EXECUTION_IMPL_PROPERTIES_HPP
3
5
6#include "Kokkos_Macros.hpp"
7#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
8import kokkos.core;
9#else
10# include "Kokkos_Core.hpp"
11#endif
12
32
34
36template <typename... Properties>
37struct properties { };
38
39namespace detail {
40
41template <template <typename...> typename T, typename... Args>
42consteval void deduce_from_base(const T<Args...>&);
43
44template <template <typename...> typename T, typename... Args>
45constexpr T<Args...>& as_base(T<Args...>& base) noexcept {
46 return base;
47}
48
49template <template <typename...> typename T, typename... Args>
50constexpr const T<Args...>& as_base(const T<Args...>& base) noexcept {
51 return base;
52}
53
54template <typename Property, typename Data>
55constexpr Property& as_base(Data& data) noexcept {
56 return data;
57}
58
59template <typename Property, typename Data>
60constexpr const Property& as_base(const Data& data) noexcept {
61 return data;
62}
63
64} // namespace detail
65
67template <typename Data, typename Property>
68consteval bool has_property() {
69 return std::derived_from<Data, Property>;
70}
71
73template <typename Data, template <typename...> typename Property>
74consteval bool has_property() {
75 return requires(const Data& data) { detail::deduce_from_base<Property>(data); };
76}
77
78template <typename Property, typename Data>
79requires(has_property<std::remove_cvref_t<Data>, Property>())
80constexpr decltype(auto) get_property(Data&& data) noexcept { // NOLINT(cppcoreguidelines-missing-std-forward)
81 return stdexec::__forward_like<Data>(detail::as_base<Property>(data).m_value);
82}
83
84template <template <typename...> typename Property, typename Data>
85requires(has_property<std::remove_cvref_t<Data>, Property>())
86constexpr decltype(auto) get_property(Data&& data) noexcept { // NOLINT(cppcoreguidelines-missing-std-forward)
87 return stdexec::__forward_like<Data>(detail::as_base<Property>(data).m_value);
88}
89
90} // namespace Kokkos::Execution::Impl
91
92#endif // KOKKOS_EXECUTION_IMPL_PROPERTIES_HPP
consteval void deduce_from_base(const T< Args... > &)
constexpr T< Args... > & as_base(T< Args... > &base) noexcept
consteval bool has_property()
Return true when Data derives from the property Property.
constexpr decltype(auto) get_property(Data &&data) noexcept
Type list of properties.