Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
ArrayConversionsUnitTestHelpers Namespace Reference

Classes

class  Array
 Replacement for std::vector that is compatible with the Teuchos Memory Management classes. More...
 
class  ArrayView
 Nonowning array view. More...
 
class  Ptr
 Simple wrapper class for raw pointers to single objects where no persisting relationship exists. More...
 
class  RCP
 Smart reference counting pointer class for automatic garbage collection. More...
 

Functions

template<class T>
Array< RCP< T > > generateArrayRcp (const Teuchos_Ordinal n_in)
 
template<class T>
Array< RCP< T > > generateArrayRcpGen (const Teuchos_Ordinal n_in)
 
template<class T>
testArrayViewInput (const ArrayView< const Ptr< const T > > &a_in)
 
template<class T>
void testArrayViewOutput (const ArrayView< const Ptr< T > > &a_out)
 
template<class T, class Dealloc_T>
TEUCHOS_DEPRECATED RCP< T > rcp (T *p, Dealloc_T dealloc, bool owns_mem)
 Deprecated.
 
template<class TypeTo, class TypeFrom>
TypeTo as (const TypeFrom &t)
 Convert from one value type to another.
 

Variables

Teuchos_Ordinal n
 

Function Documentation

◆ generateArrayRcp()

template<class T>
Array< RCP< T > > ArrayConversionsUnitTestHelpers::generateArrayRcp ( const Teuchos_Ordinal n_in)

Definition at line 63 of file ArrayConversions_UnitTest_helpers.hpp.

◆ generateArrayRcpGen()

template<class T>
Array< RCP< T > > ArrayConversionsUnitTestHelpers::generateArrayRcpGen ( const Teuchos_Ordinal n_in)

Definition at line 75 of file ArrayConversions_UnitTest_helpers.hpp.

◆ testArrayViewInput()

template<class T>
T ArrayConversionsUnitTestHelpers::testArrayViewInput ( const ArrayView< const Ptr< const T > > & a_in)

Definition at line 86 of file ArrayConversions_UnitTest_helpers.hpp.

◆ testArrayViewOutput()

template<class T>
void ArrayConversionsUnitTestHelpers::testArrayViewOutput ( const ArrayView< const Ptr< T > > & a_out)

Definition at line 98 of file ArrayConversions_UnitTest_helpers.hpp.

◆ rcp()

template<class T, class Dealloc_T>
TEUCHOS_DEPRECATED RCP< T > Teuchos::rcp ( T * p,
Dealloc_T dealloc,
bool owns_mem )
inline

Deprecated.

Definition at line 1266 of file Teuchos_RCPDecl.hpp.

◆ as()

template<class TypeTo, class TypeFrom>
TypeTo Teuchos::as ( const TypeFrom & t)
inline

Convert from one value type to another.

Template Parameters
TypeToThe type to which to convert; the output type.
TypeFromThe type from which to convert; the input type.

User documentation

This template function lets you convert from one value type to another, possibly with checks for overflow (where appropriate) in a debug build of Teuchos. For example, to convert between int and double:

double d = 3.14;
int i = Teuchos::as<double> (d);
assert (i == 3);
TypeTo as(const TypeFrom &t)
Convert from one value type to another.

In a debug build of Teuchos, this will check for overflow, since there are some double-precision floating-point values that do not fit in a 32-bit integer. In a release build, this will not check for overflow. You are responsible for knowing the difference. If you always want to check for overflow (e.g., to validate user input), use the asSafe() function. Note that conversion from a floating-point number to an integer, or from a higher-precision floating-point number to a lower-precision floating-point number, may truncate or round (as it does in the above example). We do not check for truncation or rounding.

"Debug build of Teuchos" means more than just building with debug compiler flags. It means debug checking was turned on when Trilinos was built. If you are building Trilinos yourself, you may turn on debug checking by setting the Trilinos_ENABLE_DEBUG CMake configure option to ON (rather than OFF, which is the default). Note that enabling debug checking affects other operations in Teuchos besides this conversion, and may have a significant run-time cost, especially for RCP and ArrayRCP.

The IEEE 754 standard defines the result of conversions from a larger to a smaller built-in floating-point type, including double to float, long double to float, and long double to double. Such conversions might overflow (result in a value too large in magnitude to fit in the target type) or underflow (result in a value too small to fit in a normalized value of the target type). We never check for overflow or underflow for these conversions. Their behavior depends on the current rounding mode and whether your hardware and compiler correctly implement denormalized values. Typically, overflow results in an Inf of the same sign as the input, and underflow results in either a denormalized value or zero. If you want to do bounds checking, you should set the appropriate trap so that overflow or underflow will raise the SIGFPE signal. Please refer to the IEEE 754 standard for details. Note that debug-mode as() conversions from e.g., std::string to built-in floating-point types still check for overflow.

Note
We cannot promise that converting from a type T1 to another type T2 and back again will result in the same T1 value with which we started. For example, converting from a long long to a double may result in truncation, since long long has 63 bits of significand and double has 53.

Developer documentation

This function uses the traits class ValueTypeConversionTraits to perform checking and conversion. If debug checking is turned on, this function uses the traits class' safeConvert() method to perform possibly checked conversion. Otherwise, it uses the traits class' convert() method for unchecked conversion.

If you want to specialize this function's behavior, you should specialize ValueTypeConversionTraits for your combination of input and output types (TypeFrom resp. TypeTo). Be sure to define the specialization in the Teuchos namespace. We provide specializations of ValueTypeConversionTraits in this file for a variety of types. You must define both safeConvert() and convert() in the specialization, since as() will call safeConvert() in a debug build and convert() in a release build.

Note
The implementations below do not consider truncation of floating-point values to be unsafe conversion. For example, converting from a long long (63 bits of significand) to a double (53 bits of significand) may result in truncation, but we do not consider this unsafe. "Unsafe" mainly refers to overflow or lack of representation.

Definition at line 2840 of file Teuchos_as.hpp.

Variable Documentation

◆ n

Teuchos_Ordinal ArrayConversionsUnitTestHelpers::n
extern