|
Boost : |
From: Geoff Leyland (geoff.leyland_at_[hidden])
Date: 2002-08-12 06:28:20
On Lundi, août 12, 2002, at 12:52 , "Dylan Cuthbert" <dylan_at_[hidden]>
wrote:
> Sounds cool, just one question, why do you need .vector()[3], why not
> return
> a template wrapper class for the variable that "operator TYPE"s down to
> whatever type it is, and at the same time has an operator[] that
> automatically casts the type and applies [] to it.
Good point! I've got lots of ways of getting at the object. There's a
.be<something>() and a .ref<something>(), and a few names (.str(),
.c_str(), .vector() and .map()) for common things.
I've also got a generic cast
template <class T> operator T(void);
which seemed a bit scary, 'cos I thought it would get in all over the
place, but which actually works really well, and cuts down on a lot of
.be<>()'s.
But the [] operators are an excellent idea. Cuts down on more typing!
Incidentally, there's a big difference between the .be<> and the
.ref<>. I use a "storage_type" to store the thing:
eg: template <> class storage_type<const char *> { typedef string
type; };
so that for example, all string types are strings, and all real types
are doubles etc. This means that when you do a be<>, you can cast back
to the type you wanted (so a stored double can be cast to a float), but
if you want a reference, you have to get exactly the type that's stored.
I'll have a bit of a tidy this afternoon or tonight, and put it
somewhere people can have a look at it tomorrow. Or in an "appropriate
place" if someone can confirm where that might be...
cheers,
goof
-- Geoff Leyland Laboratoire d'energetique industrielle LENI-DGM-EPFL, CH-1015, Lausanne, Switzerland Phone: +41 (21) 693 3505, Fax: +41 (21) 693 35 02
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk