
Hi Vicente, Vicente J. Botet Escriba wrote:
Le 22/08/11 22:50, Phil Endecott a ?crit :
Vicente J. Botet Escriba wrote:
If we can construct implicitly a pair from another pair of implicitly convertible types, why we couldn't allow the conversion from a pair of type that are extrinsically implicitly convertible to them?
Right. But does your library make this possible?
The specialization of the customization point implicit_convert_cp allows to convert 'implicitly' pairs of extrinsicaly convertible types using the implicit_convert_to function. Now the user ca use the explicit_convert_to function to convert these types as for example
B1 b1; B2 b2; std::pair<B1,B2> b; std::pair<A1,A2> a1(boost::conversion::explicit_convert_to<std::pair<A1,A2> >(b));
Note that implicit convertible implies explicit convertible.
I wrote implicitly with coutes because we need to use a function which makes the call explicit.
Resuming, the user wanting extrinsically implicit conversions, must use explicitly the 'implicitly' function.
I was really hoping that I had misunderstood something and that actually your library could make it possible to have extrinsic implicit conversions. But it doesn't; the conversions still require additional syntax. So they aren't implicit conversions. Since you can't add this additional syntax to e.g. the std:: algorithms, I am still struggling to see how the library is useful.
Imagine that library A defines
struct T { int i; int j; };
and library B defines
struct R { long x; long y; };
I magine now that you recover an array<T,3> from library A and that you need to use some functions in library B that need a c-array R[3].
If you stablish a conversion from T to R using convert_to and if you have that an array<T,N> can be assigned to an R[N] you could do the following
array<T,3> source; // call some functions in A that fill this array
A_f(source);
//Now you need to present this data to the B library R target[3];
// convert source to target assign_to(target,source);
// uses target in a B function
B_g(target);
Or you could just: array<T,3> source; A_f(source); R target[3]; std::transform(source.begin(),source.end(),target,&R_to_T); B_g(target); where R_to_T is the same conversion function that you need - but with the advantage that I can define multiple conversions between each pair of types, if I want to. Regards, Phil.