DPC++ Runtime
Runtime libraries for oneAPI DPC++
property_value.hpp
Go to the documentation of this file.
1 //==------ property_value.hpp --- SYCL compile-time property values --------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/ext/oneapi/properties/property.hpp> // for IsCompileTi...
12 #include <sycl/ext/oneapi/properties/property_utils.hpp> // for HasValue
13 
14 #include <type_traits> // for enable_if_t
15 
16 namespace sycl {
17 inline namespace _V1 {
18 namespace ext::oneapi::experimental {
19 namespace detail {
20 
21 // Base class for property values with a single non-type value
22 template <typename T, typename = void> struct SingleNontypePropertyValueBase {};
23 
24 template <typename T>
25 struct SingleNontypePropertyValueBase<T, std::enable_if_t<HasValue<T>::value>> {
26  static constexpr auto value = T::value;
27 };
28 
29 // Helper base class for property_value.
30 template <typename... Ts> struct PropertyValueBase {};
31 
32 template <typename T>
34  using value_t = T;
35 };
36 
37 } // namespace detail
38 
39 template <typename PropertyT, typename... Ts>
40 struct property_value : public detail::PropertyValueBase<Ts...> {
41  using key_t = PropertyT;
42 };
43 
44 template <typename PropertyT, typename... A, typename... B>
45 constexpr std::enable_if_t<detail::IsCompileTimeProperty<PropertyT>::value,
46  bool>
49  return (std::is_same<A, B>::value && ...);
50 }
51 
52 template <typename PropertyT, typename... A, typename... B>
53 constexpr std::enable_if_t<detail::IsCompileTimeProperty<PropertyT>::value,
54  bool>
57  return (!std::is_same<A, B>::value || ...);
58 }
59 
60 template <typename V, typename = void> struct is_property_value {
61  static constexpr bool value =
63 };
64 template <typename V, typename O, typename = void> struct is_property_value_of {
65  static constexpr bool value =
67 };
68 // Specialization for compile-time-constant properties
69 template <typename V>
70 struct is_property_value<V, std::void_t<typename V::key_t>>
71  : is_property_key<typename V::key_t> {};
72 template <typename V, typename O>
73 struct is_property_value_of<V, O, std::void_t<typename V::key_t>>
74  : is_property_key_of<typename V::key_t, O> {};
75 
76 namespace detail {
77 
78 // Specialization of PropertyID for propagating IDs through property_value.
79 template <typename PropertyT, typename... PropertyValueTs>
80 struct PropertyID<property_value<PropertyT, PropertyValueTs...>>
81  : PropertyID<PropertyT> {};
82 
83 // Specialization of IsCompileTimePropertyValue for property values.
84 template <typename PropertyT, typename... PropertyValueTs>
85 struct IsCompileTimePropertyValue<property_value<PropertyT, PropertyValueTs...>>
86  : IsCompileTimeProperty<PropertyT> {};
87 
88 } // namespace detail
89 } // namespace ext::oneapi::experimental
90 } // namespace _V1
91 } // namespace sycl
constexpr std::enable_if_t< detail::IsCompileTimeProperty< PropertyT >::value, bool > operator==(const property_value< PropertyT, A... > &, const property_value< PropertyT, B... > &)
constexpr std::enable_if_t< detail::IsCompileTimeProperty< PropertyT >::value, bool > operator!=(const property_value< PropertyT, A... > &, const property_value< PropertyT, B... > &)
Definition: access.hpp:18