Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-01-23 15:32:40

----- Original Message -----
From: Peter Dimov <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, January 23, 2002 5:11 PM
Subject: Re: [boost] environment variable access

> > > What about orthogonality?
> >
> > VERY good point!
> >
> > But I'm not sure if a plain string is right, tough.
> >
> > If you want to check if the external variable is there, and only then
> > it, you'll need two calls to the enviroment:
> >
> > if ( exist_in_environment["http_proxy"] )
> > foo ( environment["http_proxy"] ) ;
> >
> > AFAICT, this can be solved in 3 ways:
> [...]
> I might be missing something but why shouldn't 'environment' be a std::map
> (actually it wouldn't be a std::map but offer the same interface)?
I'm not sure if I follow you, but a map's operator [] interface doesn't tell
you if there isn't any element of the given key.
Even worse, the standard states that: map element access
reference operator[](const key_type& x);
1 Returns: (*((insert(make_pair(x, T()))).first)).second.

so, if "environment" would follow the interface exactly, it would have to
totally 'lie' and return an empty string if
the variable isn't there.
I don't think that this behavior is appropriate for external variables.

You can use find(), but then "environment" would have to define iterators,
at least '.end()' to compare against, thus
it would look too much like a finite-size sequence while it might be not.

Fernando Cacciola
Sierra s.r.l.

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