Blender V5.3
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData > Class Template Reference

#include <BLI_any.hh>

Public Member Functions

 Any ()=default
 Any (const Any &other)
 Any (Any &&other) noexcept
template<typename T, typename... Args>
 Any (std::in_place_type_t< T >, Args &&...args)
template<typename T>
requires (!is_same_any_v<T>)
 Any (T &&value)
 ~Any ()
Any & operator= (const Any &other)
template<typename T>
Any & operator= (T &&other)
void reset ()
 operator bool () const
bool has_value () const
template<typename T, typename... Args>
std::decay_t< T > & emplace (Args &&...args)
template<typename T, typename... Args>
std::decay_t< T > & emplace_on_empty (Args &&...args)
template<typename T>
void * allocate ()
template<typename T>
void * allocate_on_empty ()
template<typename T>
bool is () const
void * get ()
const void * get () const
template<typename T>
T & get ()
template<typename T>
const T & get () const
const RealExtraInfo & extra_info () const

Public Attributes

BLI_NO_UNIQUE_ADDRESS ExtraData extra = {}

Static Public Attributes

template<typename T>
static constexpr bool is_allowed_v = std::is_copy_constructible_v<T>
template<typename T>
static constexpr bool is_inline_v
template<typename T>
static constexpr bool is_same_any_v = std::is_same_v<std::decay_t<T>, Any>

Detailed Description

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
class blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >
Template Parameters
ExtraInfoEither void or a struct that contains data members for additional type information. The struct has to have a static ExtraInfo get<T>() method that initializes the struct based on a type.
InlineBufferCapacitySize of the inline buffer. This allows types that are small enough to be stored directly inside the Any without an additional allocation.
AlignmentRequired minimum alignment of the inline buffer. If this is smaller than the alignment requirement of a used type, a separate allocation is necessary.
ExtraDataDepending on the Alignment template parameter, there may be extra padding space that's available to store some data. This type is stored after the buffer to use that space.

Definition at line 107 of file BLI_any.hh.

Constructor & Destructor Documentation

◆ Any() [1/5]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::Any ( )
default

◆ Any() [2/5]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::Any ( const Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData > & other)
inline

Definition at line 167 of file BLI_any.hh.

◆ Any() [3/5]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::Any ( Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData > && other)
inlinenoexcept
Note
The #other Any will not be empty afterwards if it was not before. Just its value is in a moved-from state.

Definition at line 185 of file BLI_any.hh.

◆ Any() [4/5]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T, typename... Args>
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::Any ( std::in_place_type_t< T > ,
Args &&... args )
inlineexplicit

Constructs a new Any that contains the given type T from #args. The #std::in_place_type_t is used to disambiguate this and the copy/move constructors.

Definition at line 204 of file BLI_any.hh.

◆ Any() [5/5]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
requires (!is_same_any_v<T>)
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::Any ( T && value)
inline

Constructs a new Any that contains the given value.

Definition at line 213 of file BLI_any.hh.

◆ ~Any()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::~Any ( )
inline

Definition at line 219 of file BLI_any.hh.

Member Function Documentation

◆ allocate()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
void * blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::allocate ( )
inline

Like emplace but does not actually construct the value. The caller is responsible for calling the constructor before the value is used.

Definition at line 306 of file BLI_any.hh.

Referenced by blender::bke::SocketValueVariant::allocate(), and blender::tests::TEST().

◆ allocate_on_empty()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
void * blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::allocate_on_empty ( )
inline

Like emplace_on_empty but does not actually construct the value. The caller is responsible for calling the constructor before the value is used.

Definition at line 316 of file BLI_any.hh.

◆ emplace()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T, typename... Args>
std::decay_t< T > & blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::emplace ( Args &&... args)
inline

◆ emplace_on_empty()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T, typename... Args>
std::decay_t< T > & blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::emplace_on_empty ( Args &&... args)
inline

Definition at line 282 of file BLI_any.hh.

◆ extra_info()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
const RealExtraInfo & blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::extra_info ( ) const
inline

Get extra information that has been stored for the contained type.

Definition at line 390 of file BLI_any.hh.

◆ get() [1/4]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
T & blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::get ( )
inline

Get a reference to the stored value. This invokes undefined behavior when T does not have the correct type.

Definition at line 362 of file BLI_any.hh.

◆ get() [2/4]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
void * blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::get ( )
inline

◆ get() [3/4]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
const T & blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::get ( ) const
inline

Get a reference to the stored value. This invokes undefined behavior when T does not have the correct type.

Definition at line 372 of file BLI_any.hh.

◆ get() [4/4]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
const void * blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::get ( ) const
inline

Get a pointer to the stored value.

Definition at line 349 of file BLI_any.hh.

◆ has_value()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
bool blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::has_value ( ) const
inline

Definition at line 270 of file BLI_any.hh.

Referenced by blender::tests::TEST(), blender::tests::TEST(), and blender::tests::TEST().

◆ is()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
bool blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::is ( ) const
inline

Return true when the value that is currently stored is a T.

Definition at line 333 of file BLI_any.hh.

Referenced by blender::tests::TEST(), and blender::tests::TEST().

◆ operator bool()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::operator bool ( ) const
inline

Definition at line 265 of file BLI_any.hh.

◆ operator=() [1/2]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
Any & blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::operator= ( const Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData > & other)
inline
Note
Only needed because the template below does not count as copy assignment operator.

Definition at line 231 of file BLI_any.hh.

◆ operator=() [2/2]

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
Any & blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::operator= ( T && other)
inline

Assign any value to the Any.

Definition at line 242 of file BLI_any.hh.

◆ reset()

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
void blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::reset ( )
inline

Destruct any existing value to make it empty.

Definition at line 255 of file BLI_any.hh.

Referenced by blender::tests::TEST().

Member Data Documentation

◆ extra

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
BLI_NO_UNIQUE_ADDRESS ExtraData blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::extra = {}

Extra data potentially stored within padding required by the buffer.

Definition at line 124 of file BLI_any.hh.

◆ is_allowed_v

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
bool blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::is_allowed_v = std::is_copy_constructible_v<T>
staticconstexpr

Only copy constructible types can be stored in Any.

Definition at line 135 of file BLI_any.hh.

◆ is_inline_v

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
bool blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::is_inline_v
staticconstexpr
Initial value:
= std::is_nothrow_move_constructible_v<T> &&
sizeof(T) <= InlineBufferCapacity && alignof(T) <= Alignment
#define T

Checks if the type will be stored in the inline buffer or if it requires a separate allocation.

Definition at line 142 of file BLI_any.hh.

◆ is_same_any_v

template<typename ExtraInfo = void, size_t InlineBufferCapacity = 8, size_t Alignment = 8, typename ExtraData = blenlib_detail::EmptyType>
template<typename T>
bool blender::Any< ExtraInfo, InlineBufferCapacity, Alignment, ExtraData >::is_same_any_v = std::is_same_v<std::decay_t<T>, Any>
staticconstexpr

Checks if T is the same type as this Any, because in this case the behavior of e.g. the assignment operator is different.

Definition at line 149 of file BLI_any.hh.


The documentation for this class was generated from the following file: