CLA3P v0.3.1
Compact Linear Algebra Parallel Portable Package
Loading...
Searching...
No Matches
cla3p::Guard< T_Object > Class Template Reference

Immutable object wrapper. More...

Public Member Functions

 Guard ()
 Default constructor.
 ~Guard ()
 Destructor.
 Guard (const Guard< T_Object > &other)
 Copy constructor.
Guard< T_Object > & operator= (const Guard< T_Object > &other)
 Copy assignment operator.
template<typename U_Object>
 Guard (Guard< U_Object > &&other)
 Move converting constructor.
 Guard (const T_Object &obj)
 Object constructor.
void clear ()
 Clears the guard.
const T_Object & get () const
 Retrieves the guarded object.

Detailed Description

template<typename T_Object>
class cla3p::Guard< T_Object >

Immutable object wrapper.

Template Parameters
T_ObjectThe object type to guard.

Provides a read-only view of an object, preventing modifications to its contents. Used when functions need to return objects with immutable data that must be protected from external changes.

#include <iostream>
#include <cla3p/dense.hpp>
int main()
{
/*
* Create a constant vector
*/
/*
* Get a shallow copy of the constant vector using the Guard class
*/
/*
* Get an immutable reference of the copied vector
*/
const cla3p::dns::RdVector& y = y_grd.get();
/*
* Get info of the two vectors
*/
std::cout << x.info("x") << y.info("y") << std::endl;
return 0;
}
Immutable object wrapper.
Definition guard.hpp:37
const T_Object & get() const
Retrieves the guarded object.
Definition guard.hpp:96
std::string info(const std::string &header="") const
Get information about the vector.
XiVector< T_Scalar > rcopy()
Create a reference copy (shallow copy) of the vector.
static XxVector< real_t > random(int_t n, T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1))
XxVector< real_t > RdVector
Double precision real vector.
Definition dense.hpp:31
Examples
ex01g_dense_vector_block_operations.cpp, ex02i_dense_matrix_block_operations.cpp, ex02j_dense_matrix_column_operations.cpp, ex04a_guard_const_vector.cpp, and ex04b_guard_const_matrix.cpp.

Constructor & Destructor Documentation

◆ Guard() [1/4]

template<typename T_Object>
cla3p::Guard< T_Object >::Guard ( )
inline

Default constructor.

Constructs an empty guard with no attached object.

◆ ~Guard()

template<typename T_Object>
cla3p::Guard< T_Object >::~Guard ( )
inline

Destructor.

Detaches the guarded object and destroys the guard.

◆ Guard() [2/4]

template<typename T_Object>
cla3p::Guard< T_Object >::Guard ( const Guard< T_Object > & other)
inline

Copy constructor.

Constructs a guard with a referenced copy of other.

◆ Guard() [3/4]

template<typename T_Object>
template<typename U_Object>
cla3p::Guard< T_Object >::Guard ( Guard< U_Object > && other)
inline

Move converting constructor.

Template Parameters
U_ObjectThe source object type.

Constructs a guard by converting and moving from other.

◆ Guard() [4/4]

template<typename T_Object>
cla3p::Guard< T_Object >::Guard ( const T_Object & obj)
inlineexplicit

Object constructor.

Constructs a guard with a referenced copy of obj.

Parameters
[in]objThe object to guard.

Member Function Documentation

◆ operator=()

template<typename T_Object>
Guard< T_Object > & cla3p::Guard< T_Object >::operator= ( const Guard< T_Object > & other)
inline

Copy assignment operator.

Replaces the guarded object with a referenced copy of other.

◆ clear()

template<typename T_Object>
void cla3p::Guard< T_Object >::clear ( )
inline

Clears the guard.

Detaches the guarded object and resets the guard to an empty state.

◆ get()

template<typename T_Object>
const T_Object & cla3p::Guard< T_Object >::get ( ) const
inline

Retrieves the guarded object.

Returns a constant reference to the object being guarded.

Returns
A constant reference to the guarded object.
Examples
ex01g_dense_vector_block_operations.cpp, ex02i_dense_matrix_block_operations.cpp, ex02j_dense_matrix_column_operations.cpp, ex04a_guard_const_vector.cpp, and ex04b_guard_const_matrix.cpp.