Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2000-12-06 11:06:12


Gary Powell wrote:
> Well if we split out the "action" classes and the "sub_groups" along with
> the return_type_traits.hpp you could have a reasonable stand alone return
> type deduction system. I made the specialization for PETE, and it turned
> out to be relatively painless, although probably not obvious.
>
> // specialization to promote all native types to my type.
> template<> struct promote_code<MyType>
> { static const int value = 1000; } // long doubles are 700

Well, I am not sure if this is a right approach. My implementation of
'arithmetic_conversions_traits' uses type promotion codes (I called them
'type_rank's) too, but I consider it an implementation detail and in fact
'arithmetic_conversions_traits' (as the name suggests) works only for
built-in types. IMO, type rank makes sense only for built-in types. There is
a specific set of (pre-defined) rules in the language how (binary)
arithmetic operations work, and promotion codes or type ranks are used so
often to describe that set of rules because it just turned out that they
allow to do that in the most effective way (at least without a lot of
typing). But that doesn't mean that they are good for describing something
completely different - a behavior of user-defined types. I can't think (for
now :) of any obvious examples of problems which the technique could cause
(if there are any ;), but even then it seems too cryptic to me to be exposed
in the public interface of already not so simple library.

>
> template<class T1, class T2>
> return_type_2<arthmetic_operation<plus_action>, T1, T2 >::type
> operator+(T1 const &x, T2 const &y) {
> return x + y;
> }

I am not sure if I understand this one. Does the following code anyhow
catches your idea or I've missed the point completely?

template<class T>
struct whatever {
  whatever(T const& t = T()) : value(t) {}
  T value;
};

template<class T1, class T2>
whatever<return_type_2<arthmetic_operation<plus_action>, T1, T2 >::type>
operator+(whatever<T1> const &x, whatever<T2> const &y) {
return x.value + y.value;
}

typeof(whatever<MyType>() + whatever<int>()) == whatever<MyType> ??

> Future work, is to integrate Bill Gibbons registering of types with our
type
> resolution code.
>
That should be interesting. Could I participate? ;)

> I'm open to splitting this return type deduction code out into a separate
> library if there is enough interest. (For LL it's at the moment just an
> implementation detail.)

There is a lot of interset of having such library at boost on my side,
because
for sure I don't want to have all this code as a part of, for example,
'boost::geometry2d' :). And I think that if the library will be
understandable, relatively easy to use and work with our "favorite"
compiler,
it'll help people to write a more useful/complex C++ libraries on their own.

-Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk