ned14 / outcome

Provides very lightweight outcome<T> and result<T> (non-Boost edition)
https://ned14.github.io/outcome
Other
676 stars 62 forks source link

consuming the std::* version of outcome but using the bundled boost 1.71.0 #212

Closed emaxerrno closed 4 years ago

emaxerrno commented 4 years ago

Hi Niall,

I have boost 1.71 installed. I am using c++17. I was looking at the boost packaged one and roughly if i include

#include <boost/outcome/outcome/{ std_outcome.hpp, std_result.hpp }>

it will be the same as consuming the latest release from here ?

i do see the macro definitions are different. the docs say OUTCOME_TRY but in the souce of boost it says BOOST_OUTCOME_TRY

I'm not sure if there are other subtleties that I should be aware, or if I should just use the one from github.

I am already using std::exception_ptr and mostly a lot of the types for boost* namespace can be simply used w/ the standard types instead.

Thoughts?

ned14 commented 4 years ago

All the macros must have BOOST_ before them, as per Boost rules. Otherwise they are identical.

Yes the std_result.hpp and std_outcome.hpp headers files produce typedefs of boost::outcome::std_result<T, E> and boost::outcome::std_outcome<T, EC, EP> which would match the outcome::result<T, E> and outcome::outcome<T, EC, EP> from the standalone library.

emaxerrno commented 4 years ago

thanks! i did a small wrapper to mirror the contents of boost/outcome.hpp

#pragma once

// use the standard ones instead
#include <boost/outcome/std_outcome.hpp>
#include <boost/outcome/std_result.hpp>

// include utils
#include <outcome/iostream_support.hpp>
#include <outcome/try.hpp>
#include <outcome/utils.hpp>

template<
  class R,
  class S = std::error_code,
  class NoValuePolicy = boost::outcome::policy::default_policy<R, S, void>>
using result = boost::outcome::basic_result<R, S, NoValuePolicy>;

template<class R, class S = std::error_code>
using unchecked
  = boost::outcome::std_result<R, S, boost::outcome::policy::all_narrow>;

template<class R, class S = std::error_code>
using checked = boost::outcome::
  result<R, S, boost::outcome::policy::throw_bad_result_access<S, void>>;

Thanks!!!