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
line/config
> 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 )
      foo(a);

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

   optional<string> a = environment["http_proxy"] ;
   if ( !!a )
      foo(*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 )
      foo(a.first);

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

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk