Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-02-13 11:01:18


----- Original Message -----
From: "Geurt Vos" <G.Vos_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, February 13, 2002 12:17 PM
Subject: RE: [boost] properties in C++

>
> > For instance, this straight-forward example looks great but
> > it doesn't work:
> >
> > > boost::property<
> > > boost::read<int,A,&A::get_it>,
> > > boost::write<int,A,&A::set_it>
> > > > value;
> >
> > &A::get_it can only be a constant expression if get_it is a
> > 'static' member;
> > but a static member cannot access a property value.
> >
>
> Why isn't &A::get_it (as non-static) a constant expression?
> I have to admit I didn't look it up in the standard, but when
> I find that every real C++ compiler(*) eats it, I am not tempted
> to look it up.
>
> Geurt
>
OK. I mess up with the wording...

I'll try it again...

What I meant to say was that a member function must be bounded to an object
in order to call it.
This 'bounding' is known as a 'closure'. A closure, which doesn't exist in
C++ as a language feature, is basically a pointer to an object plus a
pointer to a member function.
Although the address of a member function is certainly a constant
expression -so you can use it as a template parameter- the address of an
object isn't, so you can't use a closure (object*+memfun*) as a template
parameter.

In your example, the object address is totally missing from the interface
and the sketch you've shown.

When you do
   A.value = 100 ;
how does the property 'value' receives &A?

My point is that there is NO WAY to store &A inside 'value' at compile time.
You can store &A::foo, but without &A this still requires runtime support.

The typical solutions that I'm aware of require the property constructor to
receive A*. Thus, 'value' cannot be default constructed and every
constructor for A requires a proper initialization of 'value'. This is the
sort of complications that usually renders the technique not too friendly
and ultimately discarded.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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