ATLAS Offline Software
Loading...
Searching...
No Matches
CaloRecGPU::Helpers::maybe_allocate< T > Struct Template Reference

Possibly holds an object in its internal buffer. More...

#include <Helpers.h>

Collaboration diagram for CaloRecGPU::Helpers::maybe_allocate< T >:

Public Member Functions

 maybe_allocate (const bool allocate, const T &t)
 maybe_allocate (const bool allocate, T &&t)
template<class ... Args>
 maybe_allocate (const bool allocate, Args &&... args)
 maybe_allocate (const maybe_allocate &other)
 maybe_allocate (maybe_allocate &&other)
maybe_allocateoperator= (const maybe_allocate &other)
maybe_allocateoperator= (maybe_allocate &&other)
 ~maybe_allocate ()
bool valid () const
T && get () &&
T & get () &
const T & get () const &
const T * operator-> () const
T * operator-> ()
 operator T& ()
 operator T&& () &&
 operator const T & () const

Private Attributes

char m_buf [sizeof(T)]
T * m_object = nullptr

Detailed Description

template<class T>
struct CaloRecGPU::Helpers::maybe_allocate< T >

Possibly holds an object in its internal buffer.

Useful to forego heap allocations, but still have the option not to construct something...

Definition at line 1920 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

Constructor & Destructor Documentation

◆ maybe_allocate() [1/5]

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const bool allocate,
const T & t )
inline

◆ maybe_allocate() [2/5]

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const bool allocate,
T && t )
inline

Definition at line 1937 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1938 {
1939 if (allocate)
1940 {
1941 m_object = new (m_buf) T(t);
1942 }
1943 }

◆ maybe_allocate() [3/5]

template<class T>
template<class ... Args>
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const bool allocate,
Args &&... args )
inline

Definition at line 1946 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1947 {
1948 if (allocate)
1949 {
1950 m_object = new (m_buf) T(std::forward<Args>(args)...);
1951 }
1952 }

◆ maybe_allocate() [4/5]

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const maybe_allocate< T > & other)
inline

◆ maybe_allocate() [5/5]

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( maybe_allocate< T > && other)
inline

Definition at line 1959 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1960 {
1961 }

◆ ~maybe_allocate()

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::~maybe_allocate ( )
inline

Definition at line 1996 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1997 {
1998 if (m_object != nullptr)
1999 {
2000 m_object->~T();
2001 }
2002 }

Member Function Documentation

◆ get() [1/3]

template<class T>
T & CaloRecGPU::Helpers::maybe_allocate< T >::get ( ) &
inline

Definition at line 2014 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2015 {
2016 return *m_object;
2017 }

◆ get() [2/3]

template<class T>
T && CaloRecGPU::Helpers::maybe_allocate< T >::get ( ) &&
inline

Definition at line 2009 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2010 {
2011 return *m_object;
2012 }

◆ get() [3/3]

template<class T>
const T & CaloRecGPU::Helpers::maybe_allocate< T >::get ( ) const &
inline

Definition at line 2019 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2020 {
2021 return *m_object;
2022 }

◆ operator const T &()

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::operator const T & ( ) const
inline

Definition at line 2044 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2045 {
2046 return *m_object;
2047 }

◆ operator T&()

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::operator T& ( )
inline

Definition at line 2034 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2035 {
2036 return *m_object;
2037 }

◆ operator T&&()

template<class T>
CaloRecGPU::Helpers::maybe_allocate< T >::operator T&& ( ) &&
inline

Definition at line 2039 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2040 {
2041 return *m_object;
2042 }

◆ operator->() [1/2]

template<class T>
T * CaloRecGPU::Helpers::maybe_allocate< T >::operator-> ( )
inline

Definition at line 2029 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2030 {
2031 return m_object;
2032 }

◆ operator->() [2/2]

template<class T>
const T * CaloRecGPU::Helpers::maybe_allocate< T >::operator-> ( ) const
inline

Definition at line 2024 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2025 {
2026 return m_object;
2027 }

◆ operator=() [1/2]

template<class T>
maybe_allocate & CaloRecGPU::Helpers::maybe_allocate< T >::operator= ( const maybe_allocate< T > & other)
inline

Definition at line 1963 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1964 {
1965 if (&other != this)
1966 {
1967 if (m_object != nullptr)
1968 {
1969 (*m_object) = other.get();
1970 }
1971 else
1972 {
1973 m_object = new (m_buf) T(other.get());
1974 }
1975 }
1976 return (*this);
1977 }

◆ operator=() [2/2]

template<class T>
maybe_allocate & CaloRecGPU::Helpers::maybe_allocate< T >::operator= ( maybe_allocate< T > && other)
inline

Definition at line 1980 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1981 {
1982 if (&other != this)
1983 {
1984 if (m_object != nullptr)
1985 {
1986 (*m_object) = other.get();
1987 }
1988 else
1989 {
1990 m_object = new (m_buf) T(other.get());
1991 }
1992 }
1993 return (*this);
1994 }

◆ valid()

template<class T>
bool CaloRecGPU::Helpers::maybe_allocate< T >::valid ( ) const
inline

Definition at line 2004 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

2005 {
2006 return m_object != nullptr;
2007 }

Member Data Documentation

◆ m_buf

template<class T>
char CaloRecGPU::Helpers::maybe_allocate< T >::m_buf[sizeof(T)]
private

◆ m_object

template<class T>
T* CaloRecGPU::Helpers::maybe_allocate< T >::m_object = nullptr
private

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