Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2006-12-02 15:43:25


AMDG

"Michael Fawcett" wrote:

> I just implemented it locally. There are probably better ways. In
> particular I dislike the static variable, but I'm not sure how one
> could do away with it. Ideas are welcome!
>
> template <typename X, typename Y, typename Z, typename W>
> struct vec4;
>
> namespace detail
> {
>
> template <typename X, typename Y = X, typename Z = Y, typename W = Z>
> struct address_of_dispatch
> {
> X *operator()(vec4<X, Y, Z, W> &rhs) const { return rhs.array(); }
> const X *operator()(const vec4<X, Y, Z, W> &rhs) const { return rhs.array(); }
> };
> template <typename X, typename Y, typename Z, typename W>
> struct address_of_dispatch<X &, Y &, Z &, W &>
> {
> X *operator()(vec4<X &, Y &, Z &, W &> &rhs) const
> {
> static vec4<X, Y, Z, W> nrv;
> nrv = rhs;
> return nrv.array();
> }
> const X *operator()(const vec4<X &, Y &, Z &, W &> &rhs) const
> {
> return (*this)(const_cast<vec4<X &, Y &, Z &, W &> &>(rhs));
> }
> };
>
> }
>
> // Inside vec4's definition
> typename boost::remove_reference<X>::type *operator&(void)
> {
> return detail::address_of_dispatch<X, Y, Z, W>()(*this);
> }
> typename boost::remove_reference<X>::type const *operator&(void) const
> {
> return detail::address_of_dispatch<X, Y, Z, W>()(*this);
> }
>
> That works...whether it's the best solution is another story...
>
Well, even whether it works is debatable.

template<class X>
void do_stuff(X*, X*);
template<class X, class Y, class Z, class W>
void f(vec4<X, Y, Z, W>&, vec4<X, Y, Z, W>&) {
    do_stuff(&arg1, &arg2);
}

> I'll update the Vault files to include these changes. Thanks for
> bringing this issue up!
>
> --Michael Fawcett
>

In Christ,
Steven Watanabe


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