Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-06-11 06:05:26


Dave,

>I guess I'm not familiar enough with the usage to be able to evaluate the
options here. What constructability guarantees are you referring to? What
is
the upshot of having a non-assignable value_type? What is the impact on
real
code?
<

I don't know - that's why it got left as it was, we need some real world
examples of usage, examples of things that break etc, (not to mention
compilers that treat references to arrays correctly).

>I wanted to use call_traits so that no matter what T was, I could:

     1. Pass T into the class (param_type)
     2. Pass T out of the class by value (value_type)
     3. Pass T out of the class by reference (reference)
     4. Pass T out of the class by const reference (const_reference)

I set up a test-bed to do this and experimented with pods, references and
arrays. The following test-bed is not a pass-fail sort of thing. You
have to study the code to decide what is "right".
<

OK, I see where you are comming from, however I had always assumed that
call_traits::value_type was the thing that you stored in the object (in
other words that arrays aren't "special" in any way), my rational was
something like make_pair, lets simplify it and call it "wrap":

template <class T>
class wrap_t
{
        typedef typename call_traits<T>::value_type value_type;
        typedef typename call_traits<T>::reference reference;
        typedef typename call_traits<T>::const_reference const_reference;
        typedef typename call_traits<T>::param_type param_type;

        value_type v;
public:
        wrap_t(param_type p) : v(p) {}
        reference get() { return v; }
        const_reference get()const { return v; }
};

template <class T>
wrap_t<T> wrap(const T& t) { return wrap_t<T>(t); }

So in this case calling wrap("abc") would instantiate wrap_t<char[4]>, and
would store a reference to the actual string literal array, arrays would
then be completely analogous to references.

BTW this behaviour would be compatable with your example (I *think*),
except that return by value would return a reference not an array - but
hold on returning an array by value isn't allowed anyway is it?

- John.


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