Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2005-11-01 20:18:34


"joel reed" <joel.reed_at_[hidden]> wrote in message
news:20051101181348.GA10833_at_ddiworld.com...
> I've been exploring what a cross platform process library would look like
> and have a question about whether there is a preferred idiom for what I'll
> call an occasional property for lack of a better term.
>
> Given a process, I'd like to be able to query the parent process. Posix
> has
> such a notion, but win32 doesn't. On posix, afaik, every process has a
> parent except for "init."
>
> I can't decide whether I should say
>
> class process
> {
> public:
> process parent();
>
> static const process nprocess; // like std::string's npos
> };
>
> where parent() != nprocess when the process has a parent.
>
> or
>
> class process
> {
> public:
> typedef std::pair<process,bool> parent_type;
> parent_type parent();
> };
>
> where parent_type.second == true when the process has a parent.
>
> I also considered a "parent_iterator", since on posix, you could keep
> walking backwards up the hierarchy till you get to init, e.g.
>
> class parent_iterator;
>
> class process
> {
> public:
> parent_iterator parent();
> };
>
> but conceptually, I couldn't see a good "end()"

Why not just use boost::optional? Then you could declare
    boost::optional<process &> parent();

One of the main uses of optional is to return data that might or might not
exist.

Joe Gottman


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