|
Teuchos - Trilinos Tools Package
Version of the Day
|
Default traits class for all conversions between value types. More...
#include <Teuchos_as.hpp>
Static Public Member Functions | |
| static TypeTo | convert (const TypeFrom t) |
| Convert t from a TypeFrom object to a TypeTo object. | |
| static TypeTo | safeConvert (const TypeFrom t) |
| Convert t from a TypeFrom object to a TypeTo object, in a more safe way. | |
Default traits class for all conversions between value types.
as() or asSafe() template functions.| TypeTo | The type to which to convert; the output type. |
| TypeFrom | The type from which to convert; the input type. |
The type conversion functions as() and asSafe() use this traits class to convert between types. The default implementation of this class simply does an implicit type conversion. Syntactically, it expects either that TypeTo have a constructor which takes a single TypeFrom argument, like this:
class TypeTo { public: TypeTo (const TypeFrom& x); }
or that TypeFrom has an "operator TypeTo()" method, like this:
class TypeFrom { public: operator TypeTo (); }
Any conversions which are built into C++ and are safe to do will not need a traits class specialization, and should not generate any compiler warnings. This includes the conversions float to double, short type to type, type to long type, or an enum value to int (where type may be either int or unsigned int).
Any conversion which is not syntactically legal according to the above rules _must_ have a specialization. There are a number of examples in the header file below, including qd_real. Other examples include std::string to int, double, etc.
Any conversion that _is_ syntactically legal, but could cause compiler warnings and/or result in incorrect behavior at run time should be given a specialization that does not rely on an implicit conversion. This includes the following:
type to and from unsigned type, where type is a built-in integer typedouble to int, or between any floating-point and integer types where overflow is possibleIf the user (through as() or asSafe()) requests a conversion for which no specialization of this class exists), then the default implementation below will be instantiated. If the conversion is not syntactically correct, then the compiler will report a compiler error. If the conversion is syntactically correct but unsafe, the compiler _may_ report a warning. In either case, you can fix the error or warning by specializing this class for your combination of types. There are a number of examples of specializations in this header file, some of which include bounds checking for overflow (for safeConvert()).
Definition at line 126 of file Teuchos_as.hpp.
| static TypeTo Teuchos::ValueTypeConversionTraits< TypeTo, TypeFrom >::convert | ( | const TypeFrom | t | ) | [inline, static] |
Convert t from a TypeFrom object to a TypeTo object.
Definition at line 129 of file Teuchos_as.hpp.
| static TypeTo Teuchos::ValueTypeConversionTraits< TypeTo, TypeFrom >::safeConvert | ( | const TypeFrom | t | ) | [inline, static] |
Convert t from a TypeFrom object to a TypeTo object, in a more safe way.
Definition at line 136 of file Teuchos_as.hpp.
1.7.6.1