Boost logo

Boost :

From: Geoff Leyland (geoff.leyland_at_[hidden])
Date: 2002-09-06 06:45:13


On Vendredi, septembre 6, 2002, at 01:21 , "Dylan Cuthbert"
<dylan_at_[hidden]> wrote:

> Looks like you've had a good play with it, I presume it supports any
> types
> now rather than the limited set you had before?

Uh, no. :-( I've been waiting for boost 1.29 for a "new" any, and
following dynamic_any, which fixes one of the problems you mentioned
earlier. And, basically, I've been lazy. I've got quite a bit of code
that uses the .be<> or .ref<> syntax, and I thought I'd wait to see what
happened with any_cast<> and extract<> before I made the changes. Of
course, ideally, the contained type will be parameterised - but there'd
have to be matching syntax for the contained type from the object
returned by a

wc_ptr ptr = a["one.two.three.four"];

ptr contains a pointer to a and the parsed path, but won't do anything
until you "use" it. This means that if a["one.two.three.four"] doesn't
exist, then

ptr.be<int>(); will throw
ptr.exists(); will return false
and
ptr = 4.0; will build any necessary parts of the path in a (hopefully)
exception safe manner, ie, a won't be changed until we've build the
contained type and any intermediate containers, and if any building
fails, no memory will be leaked (hopefully).

So if your contained type doesn't use be<>, but extract<>, you'd
probably want wc_ptr to have an extract rather than a be.

There's a .guess() partly implemented, which contains those horrible

template <class T> operator T() 's

which might be an acceptable way of doing things - I really prefer

std::map<std::string, vertex<real, vertex_less> >::size_type s =
a["the.map.size"].guess();

to

std::map<string, vertex<std::real, vertex_less> >::size_type s =
a["the.map.size"].be<std::map<std::string, vertex<real, vertex_less>
>::size_type>

(which is obviously a bit of a contrived example, but I get real ones
every day).

anyway, have a look, and see what you think. It's definitely
(obviously?) a work in progress so any feedback (from anyone) would be
cool.

cheers,
goof

--
The early bird catches the worm.
If you want something else for breakfast, get up later.
Geoff Leyland, Village Idiot
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