Boost logo

Boost :

Subject: Re: [boost] Environment Variables Library?
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2015-05-21 19:20:32

On 21/05/2015 22:59, Michael Ainsworth wrote:
> Regarding the PATH variable (and other “array-like”
character-delimited environment variables), I was thinking of
implementing this with iterators. For example:
> namespace env = boost::environment;
> environment& current = env::current_environment();
> env::variable& path = current.get(“PATH”);
> for (env::variable::iterator it = path.begin(), end = path.end(); it != end; ++it)
> {
> std::cout << *it << std::endl;
> }
> path += "/var/lib/pgsql-9.4/bin";

I would recommend against this particular style. Variables like PATH
might be accessed either as a complete string (in which case += should
do a normal string append without any separator, and the iterator would
be the string's character iterator) or as individual components; it
should be obvious which of these is being done.

If the goal is to have a cross-platform library, then I think that one
of the following should be chosen:

1. A standalone library that only provides strings and makes no attempt
to separate PATH into components.

2. A library that depends on Filesystem and provides both full-string
access as well as a cross-platform way to split PATH (and other
arbitrary variables) into Filesystem path components.

I don't think a half-measure (splitting paths but not using Filesystem)
is desirable because it compromises the goal of being a portable
library, since the path separators are different.

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