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 1875 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 1892 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1893 {
1894 if (allocate)
1895 {
1896 m_object = new (m_buf) T(t);
1897 }
1898 }

◆ 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 1901 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1902 {
1903 if (allocate)
1904 {
1905 m_object = new (m_buf) T(std::forward<Args>(args)...);
1906 }
1907 }

◆ 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 1914 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1915 {
1916 }

◆ ~maybe_allocate()

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

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

1952 {
1953 if (m_object != nullptr)
1954 {
1955 m_object->~T();
1956 }
1957 }

Member Function Documentation

◆ get() [1/3]

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

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

1970 {
1971 return *m_object;
1972 }

◆ get() [2/3]

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

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

1965 {
1966 return *m_object;
1967 }

◆ get() [3/3]

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

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

1975 {
1976 return *m_object;
1977 }

◆ operator const T &()

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

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

2000 {
2001 return *m_object;
2002 }

◆ operator T&()

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

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

1990 {
1991 return *m_object;
1992 }

◆ operator T&&()

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

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

1995 {
1996 return *m_object;
1997 }

◆ operator->() [1/2]

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

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

1985 {
1986 return m_object;
1987 }

◆ operator->() [2/2]

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

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

1980 {
1981 return m_object;
1982 }

◆ operator=() [1/2]

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

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

1919 {
1920 if (&other != this)
1921 {
1922 if (m_object != nullptr)
1923 {
1924 (*m_object) = other.get();
1925 }
1926 else
1927 {
1928 m_object = new (m_buf) T(other.get());
1929 }
1930 }
1931 return (*this);
1932 }

◆ operator=() [2/2]

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

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

1936 {
1937 if (&other != this)
1938 {
1939 if (m_object != nullptr)
1940 {
1941 (*m_object) = other.get();
1942 }
1943 else
1944 {
1945 m_object = new (m_buf) T(other.get());
1946 }
1947 }
1948 return (*this);
1949 }

◆ valid()

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

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

1960 {
1961 return m_object != nullptr;
1962 }

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: