Teuchos - Trilinos Tools Package Version of the Day
Classes | Namespaces | Functions
Teuchos_as.hpp File Reference

Definition of Teuchos::as, for conversions between types. More...

#include "Teuchos_ConfigDefs.hpp"
#include "Teuchos_Assert.hpp"
#include <limits>
#include <cstdlib>
#include <cerrno>
#include <climits>

Go to the source code of this file.

Classes

class  Teuchos::ValueTypeConversionTraits< TypeTo, TypeFrom >
 Default traits class for all conversions between value types. More...
class  Teuchos::asFunc< TypeTo >
 Function object wrapper for as(). More...
class  Teuchos::ValueTypeConversionTraits< OutType, std::string >
 Convert an std::string to a type OutType. More...
class  Teuchos::ValueTypeConversionTraits< double, std::string >
 Convert an std::string to a double. More...
class  Teuchos::ValueTypeConversionTraits< float, std::string >
 Convert an std::string to a float. More...
class  Teuchos::ValueTypeConversionTraits< long double, std::string >
 Convert an std::string to a long double. More...
class  Teuchos::ValueTypeConversionTraits< long, std::string >
 Convert an std::string to a long. More...
class  Teuchos::ValueTypeConversionTraits< unsigned long, std::string >
 Convert an std::string to an unsigned long. More...
class  Teuchos::ValueTypeConversionTraits< int, std::string >
 Convert an std::string to an int. More...
class  Teuchos::ValueTypeConversionTraits< unsigned int, std::string >
 Convert an std::string to an unsigned int. More...
class  Teuchos::ValueTypeConversionTraits< short, std::string >
 Convert an std::string to a short. More...
class  Teuchos::ValueTypeConversionTraits< unsigned short, std::string >
 Convert an std::string to an unsigned short. More...
class  Teuchos::ValueTypeConversionTraits< float, double >
 Convert from double to float. More...
class  Teuchos::ValueTypeConversionTraits< float, long double >
 Convert from long double to float. More...
class  Teuchos::ValueTypeConversionTraits< double, long double >
 Convert from long double to double. More...
class  Teuchos::ValueTypeConversionTraits< short, double >
 Convert from double to short. More...
class  Teuchos::ValueTypeConversionTraits< unsigned short, double >
 Convert from double to unsigned short. More...
class  Teuchos::ValueTypeConversionTraits< int, double >
 Convert from double to int. More...
class  Teuchos::ValueTypeConversionTraits< unsigned int, double >
 Convert from double to unsigned int. More...
class  Teuchos::ValueTypeConversionTraits< long, double >
 Convert from double to long. More...
class  Teuchos::ValueTypeConversionTraits< unsigned long, double >
 Convert from double to unsigned long. More...
class  Teuchos::ValueTypeConversionTraits< short, float >
 Convert from float to short. More...
class  Teuchos::ValueTypeConversionTraits< unsigned short, float >
 Convert from float to unsigned short. More...
class  Teuchos::ValueTypeConversionTraits< int, float >
 Convert from float to int. More...
class  Teuchos::ValueTypeConversionTraits< unsigned int, float >
 Convert from float to unsigned int. More...
class  Teuchos::ValueTypeConversionTraits< long, float >
 Convert from float to long. More...
class  Teuchos::ValueTypeConversionTraits< unsigned long, float >
 Convert from float to unsigned long. More...
class  Teuchos::ValueTypeConversionTraits< short, unsigned short >
 Convert from unsigned short to short. More...
class  Teuchos::ValueTypeConversionTraits< unsigned short, short >
 Convert from short to unsigned short. More...
class  Teuchos::ValueTypeConversionTraits< int, unsigned int >
 Convert from unsigned int to int. More...
class  Teuchos::ValueTypeConversionTraits< unsigned int, int >
 Convert from int to unsigned int. More...
class  Teuchos::ValueTypeConversionTraits< long, unsigned long >
 Convert from unsigned long to long. More...
class  Teuchos::ValueTypeConversionTraits< unsigned long, long >
 Convert from long to unsigned long. More...
class  Teuchos::ValueTypeConversionTraits< short, int >
 Convert from int to short. More...
class  Teuchos::ValueTypeConversionTraits< short, long >
 Convert from long to short. More...
class  Teuchos::ValueTypeConversionTraits< int, long >
 Convert from long to int. More...
class  Teuchos::ValueTypeConversionTraits< int, unsigned long >
 Convert from unsigned long to int. More...
class  Teuchos::ValueTypeConversionTraits< long, unsigned int >
 Convert from unsigned int to long. More...
class  Teuchos::ValueTypeConversionTraits< unsigned int, long >
 Convert from long to unsigned int. More...
class  Teuchos::ValueTypeConversionTraits< unsigned int, unsigned long >
 Convert from unsigned long to unsigned int. More...
class  Teuchos::ValueTypeConversionTraits< unsigned short, unsigned long >
 Convert from unsigned long to unsigned short. More...
class  Teuchos::ValueTypeConversionTraits< std::string, char[N]>
 Convert raw C string to std::string. More...

Namespaces

namespace  Teuchos
 

The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.


Functions

template<class TypeTo , class TypeFrom >
TypeTo Teuchos::as (const TypeFrom &t)
 Convert from one value type to another.
template<class TypeTo , class TypeFrom >
TypeTo Teuchos::asSafe (const TypeFrom &t)
 Convert from one value type to another, with validity checks if appropriate.

Detailed Description

Definition of Teuchos::as, for conversions between types.

This header file declares Teuchos::as, which is a template function that converts between two different types. For example, the following code converts from double to int:

 double d = 3.14;
 int i = Teuchos::as<double> (d);
 assert (i == 3);

In a debug build of Teuchos, this code would check for overflow when converting from double (64 bits) to int (32 bits, on most platforms these days), and throw an exception if overflow occurs. In a release build, this code would not check for overflow. Users who want to check for overflow may use the Teuchos::asSafe template function. This works the same way as Teuchos::as, except that it always checks for overflow.

This file includes definitions of a small number of useful conversions. If you want to define your own conversions, you should specialize the Teuchos::ValueTypeConversionTraits template class for the "to" and "from" types in your conversion. This automatically defines Teuchos::as and Teuchos::asSafe for your conversion.

Definition in file Teuchos_as.hpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines