Blender V4.3
BLI_parameter_pack_utils.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
14#include <tuple>
15#include <type_traits>
16
17#include "BLI_utildefines.h"
18
19namespace blender {
20
24template<typename T, T Element> struct TypeForValue {
25 static constexpr T value = Element;
26};
27
31template<typename T> struct TypeTag {
32 using type = T;
33};
34
40template<typename T, T... Elements> struct ValueSequence {
44 static constexpr size_t size() noexcept
45 {
46 return sizeof...(Elements);
47 }
48
52 template<size_t I> static constexpr T at_index()
53 {
54 static_assert(I < sizeof...(Elements));
55 return std::tuple_element_t<I, std::tuple<TypeForValue<T, Elements>...>>::value;
56 }
57
61 template<T Element> static constexpr bool contains()
62 {
63 return ((Element == Elements) || ...);
64 }
65};
66
71template<typename... T> struct TypeSequence {
75 static constexpr size_t size() noexcept
76 {
77 return sizeof...(T);
78 }
79
83 template<size_t I> using at_index = std::tuple_element_t<I, std::tuple<T...>>;
84};
85
86namespace detail {
87
88template<typename T, T Value, size_t... I>
89inline ValueSequence<T, ((I == 0) ? Value : Value)...> make_value_sequence_impl(
90 std::index_sequence<I...> /*indices*/)
91{
92 return {};
93}
94
95template<typename T, T Value1, T Value2, size_t... Value1Indices, size_t... I>
96inline ValueSequence<T,
97 (ValueSequence<size_t, Value1Indices...>::template contains<I>() ? Value1 :
98 Value2)...>
100 std::index_sequence<I...> /*indices*/)
101{
102 return {};
103};
104
105} // namespace detail
106
110template<typename T, T Value, size_t Size>
112 std::make_index_sequence<Size>()));
113
118template<typename T, T Value1, T Value2, size_t Size, size_t... Value1Indices>
120 ValueSequence<size_t, Value1Indices...>(), std::make_index_sequence<Size>()));
121
122namespace parameter_pack_utils_static_tests {
123enum class MyEnum { A, B };
124static_assert(std::is_same_v<make_value_sequence<MyEnum, MyEnum::A, 3>,
126static_assert(
127 std::is_same_v<make_two_value_sequence<MyEnum, MyEnum::A, MyEnum::B, 5, 1, 2>,
129} // namespace parameter_pack_utils_static_tests
130
131} // 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 Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves 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 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
std::tuple_element_t< I, std::tuple< T... > > at_index
static constexpr size_t size() noexcept
static constexpr size_t size() noexcept
static constexpr bool contains()