Boost logo

Boost :

From: Ivan Vecerina (ivec_at_[hidden])
Date: 2006-04-22 10:28:50

"Thorsten Ottosen" <thorsten.ottosen_at_[hidden]> wrote in message
: some simple function would allow you to write
: data.set( p / "debug" / "info" / "testfail" / at(2) , "file.hpp" );

Somehow I find it inelegant to be composing a path object
(vector of strings?) instead of directly indexing the structure.

It might be "cool" if we could write:
 pt / "debug" / "info" / "testfail" % 2 = "file.hpp" ;

But there is a problem: the desired behavior of "path access"
is not the same whether one is reading or setting a value
-- as demonstrated by the std::map::operator[] snafu:
If the path does not currently exist, we will want a 'put'
operation to succeed, while a 'get' operation should either
fail (throw an exception) or return a dummy "null" tree.

I don't have time to seriously look into this, but I'm sure
that a solution can be worked out.
In my experience, however, I have rarely(ever?) needed to
directly access a 'deep' field of a tree with a path.

IMO it would be very reasonable to initially accept ptree
without a path-access mechanism -- which can easily be
added latter -- if we find that things are already
complicated enough this way.

Just for laughs:
 put( pt ) / "debug" / "info" / "testfail" % 2 << "file.hpp" ;
 get( pt ) / "debug" / "info" / "testfail" % 2 >> var;
 tryget( pt ) / "debug" / "info" / "testfail" % 2 >> var || (var=5);
  - no explicit template params are ever specified
  - default value is optionally specified after a ||,
    but the default expression is not evaluated if not used.
But don't you ever quote me on this ! ;-)


-- <- email contact form

Boost list run by bdawes at, gregod at, cpdaniel at, john at