diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_memory_utils.hh | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_virtual_array.hh | 6 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_memory_utils_test.cc | 7 |
3 files changed, 16 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh index 14eca49d126..9a5be79b61e 100644 --- a/source/blender/blenlib/BLI_memory_utils.hh +++ b/source/blender/blenlib/BLI_memory_utils.hh @@ -498,6 +498,12 @@ inline constexpr bool is_span_convertible_pointer_v = std::is_same_v<To, const void *>); /** + * Same as #std::is_same_v but allows for checking multiple types at the same time. + */ +template<typename T, typename... Args> +inline constexpr bool is_same_any_v = (std::is_same_v<T, Args> || ...); + +/** * Inline buffers for small-object-optimization should be disable by default. Otherwise we might * get large unexpected allocations on the stack. */ diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh index 3ed9f14712e..86ac95e2c77 100644 --- a/source/blender/blenlib/BLI_virtual_array.hh +++ b/source/blender/blenlib/BLI_virtual_array.hh @@ -477,9 +477,9 @@ template<typename T> struct VArrayAnyExtraInfo { template<typename StorageT> static VArrayAnyExtraInfo get() { /* These are the only allowed types in the #Any. */ - static_assert(std::is_base_of_v<VArrayImpl<T>, StorageT> || - std::is_same_v<StorageT, const VArrayImpl<T> *> || - std::is_same_v<StorageT, std::shared_ptr<const VArrayImpl<T>>>); + static_assert( + std::is_base_of_v<VArrayImpl<T>, StorageT> || + is_same_any_v<StorageT, const VArrayImpl<T> *, std::shared_ptr<const VArrayImpl<T>>>); /* Depending on how the virtual array implementation is stored in the #Any, a different * #get_varray function is required. */ diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc index 23415e69b04..207f310d902 100644 --- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc +++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc @@ -169,4 +169,11 @@ static_assert(is_span_convertible_pointer_v<int *, const void *>); static_assert(!is_span_convertible_pointer_v<TestBaseClass *, TestChildClass *>); static_assert(!is_span_convertible_pointer_v<TestChildClass *, TestBaseClass *>); +static_assert(is_same_any_v<int, float, bool, int>); +static_assert(is_same_any_v<int, int, float>); +static_assert(is_same_any_v<int, int>); +static_assert(!is_same_any_v<int, float, bool>); +static_assert(!is_same_any_v<int, float>); +static_assert(!is_same_any_v<int>); + } // namespace blender::tests |