Blender  V3.3
BLI_parameter_pack_utils.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
12 #include <tuple>
13 #include <type_traits>
14 
15 #include "BLI_utildefines.h"
16 
17 namespace blender {
18 
22 template<typename T, T Element> struct TypeForValue {
23  static constexpr T value = Element;
24 };
25 
31 template<typename T, T... Elements> struct ValueSequence {
35  static constexpr size_t size() noexcept
36  {
37  return sizeof...(Elements);
38  }
39 
43  template<size_t I> static constexpr T at_index()
44  {
45  static_assert(I < sizeof...(Elements));
46  return std::tuple_element_t<I, std::tuple<TypeForValue<T, Elements>...>>::value;
47  }
48 
52  template<T Element> static constexpr bool contains()
53  {
54  return ((Element == Elements) || ...);
55  }
56 };
57 
62 template<typename... T> struct TypeSequence {
66  static constexpr size_t size() noexcept
67  {
68  return sizeof...(T);
69  }
70 
74  template<size_t I> using at_index = std::tuple_element_t<I, std::tuple<T...>>;
75 };
76 
77 namespace detail {
78 
79 template<typename T, T Value, size_t... I>
80 inline ValueSequence<T, ((I == 0) ? Value : Value)...> make_value_sequence_impl(
81  std::index_sequence<I...> /* indices */)
82 {
83  return {};
84 }
85 
86 template<typename T, T Value1, T Value2, size_t... Value1Indices, size_t... I>
87 inline ValueSequence<T,
88  (ValueSequence<size_t, Value1Indices...>::template contains<I>() ? Value1 :
89  Value2)...>
91  std::index_sequence<I...> /* indices */)
92 {
93  return {};
94 };
95 
96 } // namespace detail
97 
101 template<typename T, T Value, size_t Size>
102 using make_value_sequence = decltype(detail::make_value_sequence_impl<T, Value>(
103  std::make_index_sequence<Size>()));
104 
109 template<typename T, T Value1, T Value2, size_t Size, size_t... Value1Indices>
110 using make_two_value_sequence = decltype(detail::make_two_value_sequence_impl<T, Value1, Value2>(
111  ValueSequence<size_t, Value1Indices...>(), std::make_index_sequence<Size>()));
112 
113 namespace parameter_pack_utils_static_tests {
114 enum class MyEnum { A, B };
115 static_assert(std::is_same_v<make_value_sequence<MyEnum, MyEnum::A, 3>,
117 static_assert(
120 } // namespace parameter_pack_utils_static_tests
121 
122 } // namespace blender
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its and blue Hue Saturation Value
#define T
ValueSequence< T,(ValueSequence< size_t, Value1Indices... >::template contains< I >) ? Value1 :Value2)... > make_two_value_sequence_impl(ValueSequence< size_t, Value1Indices... >, std::index_sequence< I... >)
ValueSequence< T,((I==0) ? Value :Value)... > make_value_sequence_impl(std::index_sequence< I... >)
decltype(detail::make_value_sequence_impl< T, Value >(std::make_index_sequence< Size >())) make_value_sequence
decltype(detail::make_two_value_sequence_impl< T, Value1, Value2 >(ValueSequence< size_t, Value1Indices... >(), std::make_index_sequence< Size >())) make_two_value_sequence
#define I
static constexpr size_t size() noexcept
std::tuple_element_t< I, std::tuple< T... > > at_index
static constexpr size_t size() noexcept
static constexpr bool contains()