|
5.0.0
Freundlich's C++ toolkit
|
Conversions between isomorphic types.
Types can be decorated to constrain their use in a program, for example, strong typedefs, boost units and so on. This is mainly done to prevent accidental usage of their values. Sometimes, however, it is necessary to undecorate them in a generic way. Consider a range of strong typedefs of integers. To compute the size of such a range (for example as a std::size_t), the strong typedefs have to be undecorated first. Because the integer range is a generic class, it needs to know how to do this for every type.
A type T can be decorated by a type constructor D to yield D<T>. An isomorphism between T and D<T> is a pair of functions:
T undecorate(D<T>) and D<T> decorate(T) such that their compositions are the identity. How they are implemented exactly can vary for every D significantly. In fcppt, these two functions are implemented as a specialization of fcppt::type_iso::transform. A specialization needs to contain the two aforementioned functions along with the typedefs decorated_type and undecorated_type.
In general, multiple type constructors can be applied one by one to yield: D_1<...D_n<T>...>. The lifted functions that decorate and undecorate between this type and T are called fcppt::type_iso::decorate and fcppt::type_iso::undecorate.
The first example shows how the decorate and undecorate functions can be used:
The next example shows how to implement a type decoration:
| Header file | Description |
|---|---|
decorate.hpp | Contains fcppt::type_iso::decorate. |
undecorate.hpp | Contains fcppt::type_iso::undecorate. |
undecorated_type.hpp | Contains the fcppt::type_iso::undecorated_type typedef. |
transform_fwd.hpp | Contains the forward declaration of fcppt::type_iso::transform. |
strong_typedef.hpp | Bindings for fcppt.strong_typedef. |
boost_units.hpp | Bindings for Boost.Units. |
enum.hpp | Bindings for fcppt.enum. |
Classes | |
| struct | fcppt::type_iso::transform< Type, Enable > |
| Customization point for decorate/undecorate. More... | |
Typedefs | |
| template<typename Type> | |
| using | fcppt::type_iso::undecorated_type = typename fcppt::type_iso::detail::undecorated_type<Type>::type |
| The undecorated type. | |
Functions | |
| template<typename Result> | |
| Result | fcppt::type_iso::decorate (fcppt::type_iso::undecorated_type< Result > const &_value) |
| Decorates a value. | |
| template<typename Type> | |
| fcppt::type_iso::undecorated_type< Type > | fcppt::type_iso::undecorate (Type const &_value) |
| Undecorates a value. | |
| using fcppt::type_iso::undecorated_type = typename fcppt::type_iso::detail::undecorated_type<Type>::type |
The undecorated type.
Undecorates Type by removing all (nested) type constructors.
|
inline |
Decorates a value.
Decorates _value by applying all (nested) type constructors of Result.
|
inline |
Undecorates a value.
Undecorates _value by removing all (nested) type constructors.