convertible concept
This is an extension of the
Assignable
concept for two different classes.
The concept describes the construction or assignment of an
object of type X from an object of type Y.
If boost::is_same<X,Y>, then X is a model of
Assignable.
The convertible concept is going to be used all over.
It does not imply that conversions are always performed
explicitly.
It may just be a condition to allow an algorithm for two types.
Whether the conversion happens or not depends on the implementation
of the algorithm.
For example, x+=y, does not imply y is first
converted to an object of type X.
The operation +=() for X may have a specialization
for objects of type Y.
Description
Refinement of
Associated types
Notation
| Y | The type that is to be converted |
| X | The type that is converted to |
| x | Object of type X |
| y | Object of type Y |
Definitions
Valid expressions
| Name | Expression | Type requirements | Return type |
| Constructor | X(y) | Y is convertible to X | X |
| Copy constructor | X x(y) | Y is convertible to X | X |
| | X x=y | Y is convertible to X | X |
| Assignment | x=y | | X& |
Expression semantics
| Name | Expression | Precondition | Semantics | Postcondition |
| Constructor | X(y) | | | |
| Copy constructor | X x(y) | | | x is a copy of the conversion of y |
| | X x=y | | | |
| Assignment | x=y | | | x is a copy of the conversion of y |
Complexity guarantees
Invariants
Models
- short is convertible to int
- float is convertible to double
- int is convertible to double
- std::complex< float > is convertible to std::complex< double >
Notes