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
This commit is contained in:
parent
594438ef0d
commit
51a131ddbc
|
@ -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.
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue