Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-03-16 11:56:53


Gary Powell wrote:
>
> > > ->* don't
> > > work either because they have a defined return type, which is not what
> > you
> > > want in this case.
> >
> > I don't see any restrictions on ->*. What do you mean ?
> > Valentin Bonnard
> >
> >
> > --
> The problem is that what I want to write is
>
> transform(a.begin(), a.end(), b.begin(), arg1->*MemberObj);
>
> What I need to do is build a delayed expression of
> arg1::operator->*(MemberObjoffsetData), so that later I can execute it.
> operator->(), operator->*() can't tell me what's coming next.

Next ? After what ?

> Note: arg1 isn't a element of a, its a place holder.
>
> Is there a way to capture the next bit of information? (The offsetData?)

You should just store it normally:

#include <iostream>

template <class C_expr, class C, typename T>
struct PtrElementAccess { // a delayed ->* expression
    C_expr lhs; // convertible to C
    T C::* rhs; // for simplicity, the rhs is a value, not an expression
    PtrElementAccess (C_expr lhs_, T C::* rhs_): lhs(lhs_), rhs(rhs_) {}
    operator T () { return C(lhs).*rhs; }
};

template <class C_expr, class C, typename T>
PtrElementAccess<C_expr, C, T> operator->* (C_expr lhs, T C::* rhs)
{
  return PtrElementAccess<C_expr, C, T> (lhs, rhs);
}

struct my_struct {
    int mem;
};
my_struct x = { 3 };

struct Constant {
    operator my_struct () { return x; }
} cst;

int main ()
{
   int i = cst->*(&my_struct::mem);
   std::cout << i << std::endl;
}

It compiles and works fine.

> My understanding is that arg1::operator->*() must return a object whose
> member pointer has a MemberObj. If I had this offset data I could save it
> away and when the fn(*aIter pMobj) is called inside the transform, I could
> then do return pMobj->*Offset.
>
> Any help here would be appreciated.
>
> Re: operator?()
>
> In the WP '96 13.6.25->28 I see now is only for built-in operators. Too
> bad.

Yes; the note is quite explicit:

 as with all these descriptions of
candidate functions, this declaration serves only to describe
the built-in operator for purposes of overload resolution.
The operator ``?'' cannot be overloaded

-- 
Valentin Bonnard

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