Commit: 51a131ddbc2eeebd13cdc6a71b2d356267fda73e Author: Jacques Lucke Date: Mon Dec 27 16:08:11 2021 +0100 Branches: master https://developer.blender.org/rB51a131ddbc2eeebd13cdc6a71b2d356267fda73e
BLI: add utility to check if type is any specific type This adds `blender::is_same_any_v` which is the almost the same as `std::is_same_v`. The difference is that it allows for checking multiple types at the same time. Differential Revision: https://developer.blender.org/D13673 =================================================================== M source/blender/blenlib/BLI_memory_utils.hh M source/blender/blenlib/BLI_virtual_array.hh M source/blender/blenlib/tests/BLI_memory_utils_test.cc M source/blender/functions/FN_generic_virtual_array.hh M source/blender/modifiers/intern/MOD_volume_displace.cc M source/blender/nodes/NOD_geometry_exec.hh M source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc =================================================================== 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 @@ -497,6 +497,12 @@ inline constexpr bool is_span_convertible_pointer_v = /* Allow casting any pointer to const void pointers. */ 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 diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh index fc8612d6f87..6aebca51219 100644 --- a/source/blender/functions/FN_generic_virtual_array.hh +++ b/source/blender/functions/FN_generic_virtual_array.hh @@ -753,8 +753,7 @@ namespace detail { template<typename StorageT> inline GVArrayAnyExtraInfo GVArrayAnyExtraInfo::get() { static_assert(std::is_base_of_v<GVArrayImpl, StorageT> || - std::is_same_v<StorageT, const GVArrayImpl *> || - std::is_same_v<StorageT, std::shared_ptr<const GVArrayImpl>>); + is_same_any_v<StorageT, const GVArrayImpl *, std::shared_ptr<const GVArrayImpl>>); if constexpr (std::is_base_of_v<GVArrayImpl, StorageT>) { return {[](const void *buffer) { diff --git a/source/blender/modifiers/intern/MOD_volume_displace.cc b/source/blender/modifiers/intern/MOD_volume_displace.cc index fcf75040a9a..a1ca29f454c 100644 --- a/source/blender/modifiers/intern/MOD_volume_displace.cc +++ b/source/blender/modifiers/intern/MOD_volume_displace.cc @@ -203,9 +203,10 @@ struct DisplaceGridOp { template<typename GridType> void operator()() { - if constexpr (std::is_same_v<GridType, openvdb::points::PointDataGrid> || - std::is_same_v<GridType, openvdb::StringGrid> || - std::is_same_v<GridType, openvdb::MaskGrid>) { + if constexpr (blender::is_same_any_v<GridType, + openvdb::points::PointDataGrid, + openvdb::StringGrid, + openvdb::MaskGrid>) { /* We don't support displacing these grid types yet. */ return; } diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh index f225b3b94b2..2246cc29dc4 100644 --- a/source/blender/nodes/NOD_geometry_exec.hh +++ b/source/blender/nodes/NOD_geometry_exec.hh @@ -134,12 +134,8 @@ class GeoNodeExecParams { } template<typename T> - static inline constexpr bool is_field_base_type_v = std::is_same_v<T, float> || - std::is_same_v<T, int> || - std::is_same_v<T, bool> || - std::is_same_v<T, ColorGeometry4f> || - std::is_same_v<T, float3> || - std::is_same_v<T, std::string>; + static inline constexpr bool is_field_base_type_v = + is_same_any_v<T, float, int, bool, ColorGeometry4f, float3, std::string>; /** * Get the input value for the input socket with the given identifier. diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc index bf7a9f49829..1d483709a0a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc @@ -180,8 +180,7 @@ static void join_component_type(Span<GeometrySet> src_geometry_sets, GeometrySet InstancesComponent &instances = instances_geometry_set.get_component_for_write<InstancesComponent>(); - if constexpr (std::is_same_v<Component, InstancesComponent> || - std::is_same_v<Component, VolumeComponent>) { + if constexpr (is_same_any_v<Component, InstancesComponent, VolumeComponent>) { join_components(components, result); } else { _______________________________________________ Bf-blender-cvs mailing list [email protected] List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
