boostorg / system

Boost.org system module
http://boost.org/libs/system
35 stars 86 forks source link

Static functions to create error-holding result and value-holding result #93

Closed grisumbras closed 2 years ago

grisumbras commented 2 years ago

The constructors that use special tag types from namespace boost::system has the unfortunate effect that one can't write a function template that (reliably) creates a result object without including some Boost.System headers. Thus it creates a physical dependency on System. For example, see this: https://godbolt.org/z/7KsKfreKe.

This can be solved with a pair of static functions result::make_error and result::make_value.

grisumbras commented 2 years ago

BTW, while we are there, having nested type aliases for value type and error type can also be useful.

pdimov commented 2 years ago

It turned out that static functions don't work when the value type is noncopyable, so I've added in_place_value and in_place_error static members to result instead. This allows R( R::in_place_value, args... ) and R( R::in_place_error, args... ).