Boost logo

Boost :

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


----- Original Message -----
From: "Brad King" <brad.king_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, February 13, 2002 7:50 PM
Subject: Re: [boost] properties in C++

> > boost::property<A, &A::value, read<&A::get_x>, write<&A::set_x> > value;
> I don't think this can work because the type of &A::value will recursively
> go on forever, and you can't take the address of a declaration that has
> yet to be made.
>
> This implementation actually compiles and runs:
>
> #define PROPERTY(c, t, n) \
> PropertyMaker< c, t >::Property<&c::Get##n, &c::Set##n> n
>
> template <typename Class, typename Data>
> struct PropertyMaker
> {
> template <Data (Class::*Get)() const, void (Class::*Set)(Data)>
> struct Property
> {
> Class* m_Class;
> operator Data () const { return (m_Class->*Get)(); }
> void operator=(Data data) const { (m_Class->*Set)(data); }
> };
> };
>
> struct Window
> {
> int GetWidth() const { return m_Width; }
> void SetWidth(int width) { m_Width = width; }
> int GetHeight() const { return m_Height; }
> void SetHeight(int height) { m_Height = height; }
>
> union
> {
> Window* m_Self;
> PROPERTY(Window, int, Width);
> PROPERTY(Window, int, Height);
> };
>
> Window(): m_Self(this), m_Width(1), m_Height(1) {}
>
> int m_Width;
> int m_Height;
> };
>
Borland C++ 5.5.1 says:

"union member Windows::Width is of type class with operator ="

I can't get to the corresponding clauses to see if it is right; but if it
is, the technique is non conformant.

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