Boost logo

Boost :

Subject: Re: [boost] [outcome] How to drop the formal empty state
From: Peter Dimov (lists_at_[hidden])
Date: 2017-05-26 16:32:50

Niall Douglas wrote:
> But if I am writing my implementation that way, it is because there is no
> purpose here to my function returning empty. Else I would implement it
> differently.
> I appreciate that the above is me speaking vaguely from experience and
> without concrete evidence.

I usually place high value on argument from experience, even if presented
without evidence.

But in this case, you've cited

which is this:

result<file_handle> file_handle::file(file_handle::path_type _path,
file_handle::mode _mode, file_handle::creation _creation,
file_handle::caching _caching, file_handle::flag flags) noexcept
  result<file_handle> ret(file_handle(native_handle_type(), 0, 0,
std::move(_path), _caching, flags));
  native_handle_type &nativeh = ret.get()._v;
attribs_from_handle_mode_caching_and_flags(nativeh, _mode, _creation,
_caching, flags));
  nativeh.behaviour |= native_handle_type::disposition::file;
  const char *path_ = ret.value()._path.c_str();
  nativeh.fd = ::open(path_, attribs, 0x1b0 /*660*/);
  if(-1 == nativeh.fd)
    return make_errored_result<file_handle>(errno,
  if(!(flags & flag::disable_safety_unlinks))
  if(_creation == creation::truncate &&
  return ret;

Now, the first line constructs

  result<file_handle> ret(file_handle(native_handle_type(), 0, 0,
std::move(_path), _caching, flags));

and it's immediately apparent that returning `ret` in this initial state
makes no sense. That is, you either need to further initialize it into a
valid file_handle, or return an "errored" result.

For this reason, I'd think that a style that does

    file_handle fh(native_handle_type(), 0, 0, std::move(_path), _caching,

first, then initializes it appropriately, and as a final step returns it via
result<file_handle>, would perhaps make more sense (and also save a number
of ret.value() calls).

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