Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Peder Holt (peder.holt_at_[hidden])
Date: 2009-10-20 16:29:08


<snip>

> Thanks ! Very clever. The self() idea is very worthy, and I may steal it
> for my own idea/implementation about "property" in C++, which I have been
> working on indefinitely ( may never get completed to my satisfaction ). The
> metaprogramming is breathtaking, if I can slowly figure it out <g> . In my
> own implementation a "property" does not need to be nested class but can
> exist as a global/static object, so I don't know how I can use your self()
> idea but I really appreciate your doing it and publishing it.
>
Thank you :)

It would be very interesting to look at your implementation to see how you
tackle the problem. Have you posted your code anywhere that I can look?

Actually, the property implementation does not have to be a nested class.
The following:
template<typename Base>
class Property_Length : public Base {
public:
   const double& get() const {
        return sqrt(
             Base::self()->X*Base::self()->X+
             Base::self()->Y*Base::self()->Y+
             Base::self()->Z*Base::self()->Z
        );
    }
};
template<typename Base>
class Property_Double : public Base {
public:
   const double& get() const {return m_arg;}
   void set(const double& arg) {m_arg=arg;}
private:
   double m_arg;
};
class Vector {
public:
    BOOST_PROPERTY(Vector,Property_Double,X);
    BOOST_PROPERTY(Vector,Property_Double,Y);
    BOOST_PROPERTY(Vector,Property_Double,Z);
    BOOST_PROPERTY(Vector,Property_Length,Length);
};

is legal. (but untested.)

Regards
Peder

>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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