Boost logo

Boost :

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

----- Original Message -----
From: <nbecker_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, January 23, 2002 4:47 PM
Subject: Re: [boost] environment variable access

> >> What I'd like (and what I'm trying to implement in command
> file
> >> parser) is map like interface. So that one could be able to say
> >>
> >> environment["http_proxy"].as<ip_address>()
> >>
> >> where "as" method is a shortcut to lexical_cast/any_cast.
> 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 get
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:

1) Return a proxy which holds the string and some way to test if it is
initialized, such as:

   external_var a = environment["http_proxy"] ;
   if ( !!a )

2) Honor orthogonbality by using the 'optional<>' class which I presented
some time ago:

   optional<string> a = environment["http_proxy"] ;
   if ( !!a )

This aproach requires operator [] to return optional<string>.

3) Mimic the optional<> behaviour, cluttering the interface:

   pair<string,bool> a = environment["http_proxy"] ;
   if ( a.second )

This aproach requires operator [] to return pair<string,bool>.

Fernando Cacciola
Sierra s.r.l.

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