Boost logo

Boost :

From: Dylan Cuthbert (dylan_at_[hidden])
Date: 2002-08-12 08:56:51


> template <class T> operator T(void);

*this* is probably Not a Good Idea ;-)

Also, you will probably have to remove the fixed "class" accessors, like
c_str() etc. in order for it to be general enough, just stick with having to
type the class name inbetween <>'s, its probably safer to have the user
specify the type precisely.

The only problem of course, is getting the auto-conversion between
floats/ints (numerics) working. I can't think of a good way unfortunately.
This problem and base-classes, ie. say a Dog with an Animal base class was
stored, and I try to access the variable by specifying just "Animal" as its
type, right now, my system will report a mismatched type and not allow it.

Regards

---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com
P2P internet radio - http://www.peercast.org

"Geoff Leyland" <geoff.leyland_at_[hidden]> wrote in message
news:9A91E041-ADE6-11D6-ABCF-003065F9F514_at_epfl.ch...
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
_______________________________________________
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