Lazy  1.0
Classes | Public Types | Public Member Functions | Friends | List of all members
lazy::Lazy< T > Class Template Referencefinal

Lazy class used for lazy-loading any type. More...

#include <Lazy.hpp>

Public Types

using this_type = Lazy< T >
 
using value_type = T
 
using pointer = T *
 
using reference = T &
 

Public Member Functions

 Lazy ()
 Default constructor; no initialization takes place.
 
template<typename CtorFunc , typename DtorFunc = void(value_type&), typename = typename std::enable_if<detail::is_callable<CtorFunc>::value>::type, typename = typename std::enable_if<detail::is_callable<DtorFunc>::value>::type>
 Lazy (const CtorFunc &constructor, const DtorFunc &destructor=default_destructor)
 Constructs a Lazy given the constructor and destructor functions. More...
 
 Lazy (const Lazy< T > &rhs)
 Constructs a Lazy by copying another Lazy. More...
 
 Lazy (Lazy< T > &&rhs)
 Constructs a Lazy by moving another Lazy. More...
 
 Lazy (const value_type &rhs)
 Constructs a Lazy by calling T's copy constructor. More...
 
 Lazy (value_type &&rhs)
 Constructs a Lazy from a given rvalue T. More...
 
 ~Lazy ()
 Destructs this Lazy and it's T.
 
this_typeoperator= (const this_type &rhs)
 Assigns a Lazy to this Lazy. More...
 
this_typeoperator= (this_type &&rhs)
 Assigns a Lazy to this Lazy. More...
 
value_type & operator= (const value_type &rhs)
 Assigns a T to this Lazy. More...
 
value_type & operator= (value_type &&rhs)
 Assigns an rvalue T to this Lazy. More...
 
 operator reference () const
 Converts this Lazy into a reference. More...
 
 operator bool () const noexcept
 Checks whether this Lazy has an instantiated object. More...
 
void swap (Lazy< T > &rhs) noexcept
 Swapperator class for no-exception swapping. More...
 
bool is_initialized () const noexcept
 Boolean to check if this Lazy is initialized. More...
 
pointer get () const
 Gets a pointer to the underlying type. More...
 
reference operator* () const
 Dereferences this Lazy object into the lazy-loaded object. More...
 
pointer operator-> () const
 Dereferences this Lazy object into the lazy-loaded object. More...
 

Friends

template<typename U , typename... Args>
Lazy< U > make_lazy (Args &&...args)
 Convenience utility to construct a Lazy object by specifying T's constructor signature. More...
 

Detailed Description

template<typename T>
class lazy::Lazy< T >

Lazy class used for lazy-loading any type.

The stored lazy-loaded class, T, will always be instantiated before being accessed, and destructed when put out of scope.

Template Parameters
Tthe type contained within this Lazy

Constructor & Destructor Documentation

template<typename T>
template<typename CtorFunc , typename DtorFunc = void(value_type&), typename = typename std::enable_if<detail::is_callable<CtorFunc>::value>::type, typename = typename std::enable_if<detail::is_callable<DtorFunc>::value>::type>
lazy::Lazy< T >::Lazy ( const CtorFunc &  constructor,
const DtorFunc &  destructor = default_destructor 
)
explicit

Constructs a Lazy given the constructor and destructor functions.

Note
The constructor function must return a std::tuple containing the arguments to pass to T's constructor for lazy-construction
Parameters
constructorfunction to use for construction
destructorfunction to use prior to destruction
template<typename T>
lazy::Lazy< T >::Lazy ( const Lazy< T > &  rhs)

Constructs a Lazy by copying another Lazy.

Note
If rhs is initialized, then this copy will also be initialized
Parameters
rhsthe Lazy to copy
template<typename T>
lazy::Lazy< T >::Lazy ( Lazy< T > &&  rhs)

Constructs a Lazy by moving another Lazy.

Note
If rhs is initialized, then this moved version will also be initialized
Parameters
rhsthe Lazy to move
template<typename T>
lazy::Lazy< T >::Lazy ( const value_type &  rhs)
explicit

Constructs a Lazy by calling T's copy constructor.

Note
This does not initialize the Lazy. Instead, it stores this value as a copy and move-constructs it later, if necessary
Parameters
rhsthe T to copy
template<typename T>
lazy::Lazy< T >::Lazy ( value_type &&  rhs)
explicit

Constructs a Lazy from a given rvalue T.

Note
This does not initialize the Lazy. Instead, it stores this value as a copy and move-constructs it later, if necessary
Parameters
rhsthe T to move

Member Function Documentation

template<typename T>
pointer lazy::Lazy< T >::get ( ) const

Gets a pointer to the underlying type.

Note
This has been added to have a similar API to smart pointers
Returns
the pointer to the underlying type
template<typename T>
bool lazy::Lazy< T >::is_initialized ( ) const
noexcept

Boolean to check if this Lazy is initialized.

Returns
true if the underlying type T is initialized.
template<typename T>
lazy::Lazy< T >::operator bool ( ) const
explicitnoexcept

Checks whether this Lazy has an instantiated object.

Returns
true if this lazy has an instantiated object
template<typename T>
lazy::Lazy< T >::operator reference ( ) const
explicit

Converts this Lazy into a reference.

Returns
the reference to the lazy-loaded object
template<typename T>
reference lazy::Lazy< T >::operator* ( ) const

Dereferences this Lazy object into the lazy-loaded object.

Returns
a constant reference to the lazy-loaded object
template<typename T>
pointer lazy::Lazy< T >::operator-> ( ) const

Dereferences this Lazy object into the lazy-loaded object.

Returns
a pointer to the lazy-loaded object
template<typename T>
this_type& lazy::Lazy< T >::operator= ( const this_type rhs)

Assigns a Lazy to this Lazy.

Note
This will construct a new T if the Lazy is not already initialized, otherwise it will assign
Parameters
rhsthe Lazy on the right-side of the assignment
Returns
reference to (*this)
template<typename T>
this_type& lazy::Lazy< T >::operator= ( this_type &&  rhs)

Assigns a Lazy to this Lazy.

Note
This will construct a new T if the Lazy is not already initialized, otherwise it will assign
Parameters
rhsthe rvalue Lazy on the right-side of the assignment
Returns
reference to (*this)
template<typename T>
value_type& lazy::Lazy< T >::operator= ( const value_type &  rhs)

Assigns a T to this Lazy.

Note
This will construct a new T if the Lazy is not already initialized, otherwise it will assign
Parameters
rhsthe T on the right-side of the assignment
Returns
reference to (ptr())
template<typename T>
value_type& lazy::Lazy< T >::operator= ( value_type &&  rhs)

Assigns an rvalue T to this Lazy.

Note
This will construct a new T if the Lazy is not already initialized, otherwise it will assign
Parameters
rhsthe T on the right-side of the assignment
Returns
reference to (ptr())
template<typename T>
void lazy::Lazy< T >::swap ( Lazy< T > &  rhs)
noexcept

Swapperator class for no-exception swapping.

Parameters
rhsthe rhs to swap

Friends And Related Function Documentation

template<typename T>
template<typename U , typename... Args>
Lazy<U> make_lazy ( Args &&...  args)
friend

Convenience utility to construct a Lazy object by specifying T's constructor signature.

The arguments are stored by copy until the object is constructed in order to avoid dangling references.

Parameters
argsthe arguments to the constructor
Returns
an instance of the Lazy object

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