Boost logo

Boost :

Subject: Re: [boost] [system][filesystem v3] A possible error_code argument compromise
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-10-27 12:48:21


Am Tuesday 27 October 2009 15:13:21 schrieb Scott McMurray:
>
> struct optional_error_code_ref {
> optional_error_code_ref() : p_() {}
> optional_error_code_ref(optional_error_code_ref const &ecr) :
> p_(ecr.p_) {}
> optional_error_code_ref(error_code &r) : p_(&r) {}
> error_code &operator*() const { return *p_; }
> error_code *operator->() const { return p_; }
> operator safe_bool() const { return safe_bool(p_); }
> private:
> error_code *p_;
> };
>
>
> It would of course be better spelt qux<error_code&>, but I'm not sure
> exactly what name that should be.

boost::optional<error_code&>?
optional does have implicit conversion and the rest of your public interface.

optional<T &> is implemented as a container of T & plus a bool though, but I
see no reason not to create a boost::optional specialization that implements
optional<T &> by holding a pointer that's exposed as a reference in the
interface.


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