feat():initial version
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/* Exception observers for outcome type
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
|
||||
File Created: Oct 2017
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
|
||||
#define BOOST_OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_HPP
|
||||
|
||||
#include "basic_result_storage.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_exception_observers : public Base
|
||||
{
|
||||
public:
|
||||
using exception_type = P;
|
||||
using Base::Base;
|
||||
|
||||
constexpr inline exception_type &assume_exception() & noexcept;
|
||||
constexpr inline const exception_type &assume_exception() const &noexcept;
|
||||
constexpr inline exception_type &&assume_exception() && noexcept;
|
||||
constexpr inline const exception_type &&assume_exception() const &&noexcept;
|
||||
|
||||
constexpr inline exception_type &exception() &;
|
||||
constexpr inline const exception_type &exception() const &;
|
||||
constexpr inline exception_type &&exception() &&;
|
||||
constexpr inline const exception_type &&exception() const &&;
|
||||
};
|
||||
|
||||
// Exception observers not present
|
||||
template <class Base, class R, class S, class NoValuePolicy> class basic_outcome_exception_observers<Base, R, S, void, NoValuePolicy> : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base;
|
||||
constexpr void assume_exception() const noexcept { NoValuePolicy::narrow_exception_check(this); }
|
||||
constexpr void exception() const { NoValuePolicy::wide_exception_check(this); }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
/* Exception observers for outcome type
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
|
||||
File Created: Oct 2017
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
|
||||
#define BOOST_OUTCOME_BASIC_OUTCOME_EXCEPTION_OBSERVERS_IMPL_HPP
|
||||
|
||||
#include "basic_outcome_exception_observers.hpp"
|
||||
|
||||
#include "../policy/base.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
|
||||
namespace policy
|
||||
{
|
||||
template <class R, class S, class P, class NoValuePolicy, class Impl> inline constexpr auto &&base::_exception(Impl &&self) noexcept
|
||||
{
|
||||
// Impl will be some internal implementation class which has no knowledge of the _ptr stored
|
||||
// beneath it. So statically cast, preserving rvalue and constness, to the derived class.
|
||||
using Outcome = BOOST_OUTCOME_V2_NAMESPACE::detail::rebind_type<basic_outcome<R, S, P, NoValuePolicy>, decltype(self)>;
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1920
|
||||
// VS2017 tries a copy construction in the correct implementation despite that Outcome is always a rvalue or lvalue ref! :(
|
||||
basic_outcome<R, S, P, NoValuePolicy> &_self = (basic_outcome<R, S, P, NoValuePolicy> &) (self); // NOLINT
|
||||
#else
|
||||
Outcome _self = static_cast<Outcome>(self); // NOLINT
|
||||
#endif
|
||||
return static_cast<Outcome>(_self)._ptr;
|
||||
}
|
||||
} // namespace policy
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() & noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_exception_check(*this);
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
|
||||
}
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_exception_check(*this);
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
|
||||
}
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() && noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_exception_check(std::move(*this));
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
|
||||
}
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::assume_exception() const &&noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_exception_check(std::move(*this));
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
|
||||
}
|
||||
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &
|
||||
{
|
||||
NoValuePolicy::wide_exception_check(*this);
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
|
||||
}
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &
|
||||
{
|
||||
NoValuePolicy::wide_exception_check(*this);
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(*this);
|
||||
}
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() &&
|
||||
{
|
||||
NoValuePolicy::wide_exception_check(std::move(*this));
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
|
||||
}
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> inline constexpr const typename basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception_type &&basic_outcome_exception_observers<Base, R, S, P, NoValuePolicy>::exception() const &&
|
||||
{
|
||||
NoValuePolicy::wide_exception_check(std::move(*this));
|
||||
return NoValuePolicy::template _exception<R, S, P, NoValuePolicy>(std::move(*this));
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/* Failure observers for outcome type
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
|
||||
File Created: Oct 2017
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
|
||||
#define BOOST_OUTCOME_BASIC_OUTCOME_FAILURE_OBSERVERS_HPP
|
||||
|
||||
#include "basic_result_storage.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace adl
|
||||
{
|
||||
struct search_detail_adl
|
||||
{
|
||||
};
|
||||
// Do NOT use template requirements here!
|
||||
template <class S, typename = decltype(basic_outcome_failure_exception_from_error(std::declval<S>()))>
|
||||
inline auto _delayed_lookup_basic_outcome_failure_exception_from_error(const S &ec, search_detail_adl /*unused*/)
|
||||
{
|
||||
// ADL discovered
|
||||
return basic_outcome_failure_exception_from_error(ec);
|
||||
}
|
||||
} // namespace adl
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1923 // VS2019
|
||||
// VS2017 and VS2019 with /permissive- chokes on the correct form due to over eager early instantiation.
|
||||
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) { static_assert(sizeof(S) == 0, "No specialisation for these error and exception types available!"); }
|
||||
#else
|
||||
template <class S, class P> inline void _delayed_lookup_basic_outcome_failure_exception_from_error(...) = delete; // NOLINT No specialisation for these error and exception types available!
|
||||
#endif
|
||||
|
||||
template <class exception_type> inline exception_type current_exception_or_fatal(std::exception_ptr e) { std::rethrow_exception(e); }
|
||||
template <> inline std::exception_ptr current_exception_or_fatal<std::exception_ptr>(std::exception_ptr e) { return e; }
|
||||
|
||||
template <class Base, class R, class S, class P, class NoValuePolicy> class basic_outcome_failure_observers : public Base
|
||||
{
|
||||
public:
|
||||
using exception_type = P;
|
||||
using Base::Base;
|
||||
|
||||
exception_type failure() const noexcept
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
#endif
|
||||
{
|
||||
if(this->_state._status.have_exception())
|
||||
{
|
||||
return this->assume_exception();
|
||||
}
|
||||
if(this->_state._status.have_error())
|
||||
{
|
||||
return _delayed_lookup_basic_outcome_failure_exception_from_error(this->assume_error(), adl::search_detail_adl());
|
||||
}
|
||||
return exception_type();
|
||||
}
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
catch(...)
|
||||
{
|
||||
// Return the failure if exception_type is std::exception_ptr,
|
||||
// otherwise terminate same as throwing an exception inside noexcept
|
||||
return current_exception_or_fatal<exception_type>(std::current_exception());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
/* Error observers for a very simple basic_result type
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
|
||||
File Created: Oct 2017
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
|
||||
#define BOOST_OUTCOME_BASIC_RESULT_ERROR_OBSERVERS_HPP
|
||||
|
||||
#include "basic_result_storage.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Base, class EC, class NoValuePolicy> class basic_result_error_observers : public Base
|
||||
{
|
||||
public:
|
||||
using error_type = EC;
|
||||
using Base::Base;
|
||||
|
||||
constexpr error_type &assume_error() & noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &>(*this));
|
||||
return this->_error;
|
||||
}
|
||||
constexpr const error_type &assume_error() const &noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &>(*this));
|
||||
return this->_error;
|
||||
}
|
||||
constexpr error_type &&assume_error() && noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_error_check(static_cast<basic_result_error_observers &&>(*this));
|
||||
return static_cast<error_type &&>(this->_error);
|
||||
}
|
||||
constexpr const error_type &&assume_error() const &&noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_error_check(static_cast<const basic_result_error_observers &&>(*this));
|
||||
return static_cast<const error_type &&>(this->_error);
|
||||
}
|
||||
|
||||
constexpr error_type &error() &
|
||||
{
|
||||
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &>(*this));
|
||||
return this->_error;
|
||||
}
|
||||
constexpr const error_type &error() const &
|
||||
{
|
||||
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &>(*this));
|
||||
return this->_error;
|
||||
}
|
||||
constexpr error_type &&error() &&
|
||||
{
|
||||
NoValuePolicy::wide_error_check(static_cast<basic_result_error_observers &&>(*this));
|
||||
return static_cast<error_type &&>(this->_error);
|
||||
}
|
||||
constexpr const error_type &&error() const &&
|
||||
{
|
||||
NoValuePolicy::wide_error_check(static_cast<const basic_result_error_observers &&>(*this));
|
||||
return static_cast<const error_type &&>(this->_error);
|
||||
}
|
||||
};
|
||||
template <class Base, class NoValuePolicy> class basic_result_error_observers<Base, void, NoValuePolicy> : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base;
|
||||
constexpr void assume_error() const noexcept { NoValuePolicy::narrow_error_check(*this); }
|
||||
constexpr void error() const { NoValuePolicy::wide_error_check(*this); }
|
||||
};
|
||||
} // namespace detail
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,158 @@
|
||||
/* Finaliser for a very simple result type
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
|
||||
File Created: Oct 2017
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_BASIC_RESULT_FINAL_HPP
|
||||
#define BOOST_OUTCOME_BASIC_RESULT_FINAL_HPP
|
||||
|
||||
#include "basic_result_error_observers.hpp"
|
||||
#include "basic_result_value_observers.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class R, class EC, class NoValuePolicy> using select_basic_result_impl = basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, EC, NoValuePolicy>, R, NoValuePolicy>, EC, NoValuePolicy>;
|
||||
|
||||
template <class R, class S, class NoValuePolicy>
|
||||
class basic_result_final
|
||||
#if defined(BOOST_OUTCOME_DOXYGEN_IS_IN_THE_HOUSE)
|
||||
: public basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, S, NoValuePolicy>, R, NoValuePolicy>, S, NoValuePolicy>
|
||||
#else
|
||||
: public select_basic_result_impl<R, S, NoValuePolicy>
|
||||
#endif
|
||||
{
|
||||
using base = select_basic_result_impl<R, S, NoValuePolicy>;
|
||||
|
||||
public:
|
||||
using base::base;
|
||||
|
||||
constexpr explicit operator bool() const noexcept { return this->_state._status.have_value(); }
|
||||
constexpr bool has_value() const noexcept { return this->_state._status.have_value(); }
|
||||
constexpr bool has_error() const noexcept { return this->_state._status.have_error(); }
|
||||
constexpr bool has_exception() const noexcept { return this->_state._status.have_exception(); }
|
||||
constexpr bool has_lost_consistency() const noexcept { return this->_state._status.have_lost_consistency(); }
|
||||
constexpr bool has_failure() const noexcept { return this->_state._status.have_error() || this->_state._status.have_exception(); }
|
||||
|
||||
BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()), //
|
||||
BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
|
||||
constexpr bool operator==(const basic_result_final<T, U, V> &o) const noexcept( //
|
||||
noexcept(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
|
||||
{
|
||||
if(this->_state._status.have_value() && o._state._status.have_value())
|
||||
{
|
||||
return this->_state._value == o._state._value; // NOLINT
|
||||
}
|
||||
if(this->_state._status.have_error() && o._state._status.have_error())
|
||||
{
|
||||
return this->_error == o._error;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class T)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<R>() == std::declval<T>()))
|
||||
constexpr bool operator==(const success_type<T> &o) const noexcept( //
|
||||
noexcept(std::declval<R>() == std::declval<T>()))
|
||||
{
|
||||
if(this->_state._status.have_value())
|
||||
{
|
||||
return this->_state._value == o.value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
constexpr bool operator==(const success_type<void> &o) const noexcept
|
||||
{
|
||||
(void) o;
|
||||
return this->_state._status.have_value();
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class T)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<S>() == std::declval<T>()))
|
||||
constexpr bool operator==(const failure_type<T, void> &o) const noexcept( //
|
||||
noexcept(std::declval<S>() == std::declval<T>()))
|
||||
{
|
||||
if(this->_state._status.have_error())
|
||||
{
|
||||
return this->_error == o.error();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()), //
|
||||
BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
|
||||
constexpr bool operator!=(const basic_result_final<T, U, V> &o) const noexcept( //
|
||||
noexcept(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
|
||||
{
|
||||
if(this->_state._status.have_value() && o._state._status.have_value())
|
||||
{
|
||||
return this->_state._value != o._state._value;
|
||||
}
|
||||
if(this->_state._status.have_error() && o._state._status.have_error())
|
||||
{
|
||||
return this->_error != o._error;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class T)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<R>() != std::declval<T>()))
|
||||
constexpr bool operator!=(const success_type<T> &o) const noexcept( //
|
||||
noexcept(std::declval<R>() != std::declval<T>()))
|
||||
{
|
||||
if(this->_state._status.have_value())
|
||||
{
|
||||
return this->_state._value != o.value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
constexpr bool operator!=(const success_type<void> &o) const noexcept
|
||||
{
|
||||
(void) o;
|
||||
return !this->_state._status.have_value();
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class T)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<S>() != std::declval<T>()))
|
||||
constexpr bool operator!=(const failure_type<T, void> &o) const noexcept( //
|
||||
noexcept(std::declval<S>() != std::declval<T>()))
|
||||
{
|
||||
if(this->_state._status.have_error())
|
||||
{
|
||||
return this->_error != o.error();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
template <class T, class U, class V, class W> constexpr inline bool operator==(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
|
||||
template <class T, class U, class V, class W> constexpr inline bool operator==(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
|
||||
template <class T, class U, class V, class W> constexpr inline bool operator!=(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
|
||||
template <class T, class U, class V, class W> constexpr inline bool operator!=(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
|
||||
} // namespace detail
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,324 @@
|
||||
/* Storage for a very simple basic_result type
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
|
||||
File Created: Oct 2017
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_BASIC_RESULT_STORAGE_HPP
|
||||
#define BOOST_OUTCOME_BASIC_RESULT_STORAGE_HPP
|
||||
|
||||
#include "../success_failure.hpp"
|
||||
#include "../trait.hpp"
|
||||
#include "value_storage.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class State, class E> constexpr inline void _set_error_is_errno(State & /*unused*/, const E & /*unused*/) {}
|
||||
template <class R, class EC, class NoValuePolicy> class basic_result_storage;
|
||||
} // namespace detail
|
||||
|
||||
namespace hooks
|
||||
{
|
||||
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept;
|
||||
template <class R, class S, class NoValuePolicy>
|
||||
constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept;
|
||||
} // namespace hooks
|
||||
|
||||
namespace policy
|
||||
{
|
||||
struct base;
|
||||
} // namespace policy
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool value_throws, bool error_throws> struct basic_result_storage_swap;
|
||||
template <class R, class EC, class NoValuePolicy> //
|
||||
class basic_result_storage
|
||||
{
|
||||
static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
|
||||
static_assert(trait::type_can_be_used_in_basic_result<EC>, "The type S cannot be used in a basic_result");
|
||||
static_assert(std::is_void<EC>::value || std::is_default_constructible<EC>::value, "The type S must be void or default constructible");
|
||||
|
||||
friend struct policy::base;
|
||||
template <class T, class U, class V> //
|
||||
friend class basic_result_storage;
|
||||
template <class T, class U, class V> friend class basic_result_final;
|
||||
template <class T, class U, class V>
|
||||
friend constexpr inline uint16_t hooks::spare_storage(const detail::basic_result_storage<T, U, V> *r) noexcept; // NOLINT
|
||||
template <class T, class U, class V>
|
||||
friend constexpr inline void hooks::set_spare_storage(detail::basic_result_storage<T, U, V> *r, uint16_t v) noexcept; // NOLINT
|
||||
template <bool value_throws, bool error_throws> struct basic_result_storage_swap;
|
||||
|
||||
struct disable_in_place_value_type
|
||||
{
|
||||
};
|
||||
struct disable_in_place_error_type
|
||||
{
|
||||
};
|
||||
|
||||
protected:
|
||||
using _value_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_value_type, R>;
|
||||
using _error_type = std::conditional_t<std::is_same<R, EC>::value, disable_in_place_error_type, EC>;
|
||||
|
||||
using _state_type = value_storage_select_impl<_value_type>;
|
||||
|
||||
#ifdef BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE
|
||||
detail::value_storage_trivial<_value_type> _state;
|
||||
#else
|
||||
_state_type _state;
|
||||
#endif
|
||||
devoid<_error_type> _error;
|
||||
|
||||
public:
|
||||
// Used by iostream support to access state
|
||||
_state_type &_iostreams_state() { return _state; }
|
||||
const _state_type &_iostreams_state() const { return _state; }
|
||||
|
||||
// Hack to work around MSVC bug in /permissive-
|
||||
_state_type &_msvc_nonpermissive_state() { return _state; }
|
||||
devoid<_error_type> &_msvc_nonpermissive_error() { return _error; }
|
||||
|
||||
protected:
|
||||
basic_result_storage() = default;
|
||||
basic_result_storage(const basic_result_storage &) = default; // NOLINT
|
||||
basic_result_storage(basic_result_storage &&) = default; // NOLINT
|
||||
basic_result_storage &operator=(const basic_result_storage &) = default; // NOLINT
|
||||
basic_result_storage &operator=(basic_result_storage &&) = default; // NOLINT
|
||||
~basic_result_storage() = default;
|
||||
|
||||
template <class... Args>
|
||||
constexpr explicit basic_result_storage(in_place_type_t<_value_type> _,
|
||||
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, Args...>)
|
||||
: _state{_, static_cast<Args &&>(args)...}
|
||||
, _error()
|
||||
{
|
||||
}
|
||||
template <class U, class... Args>
|
||||
constexpr basic_result_storage(in_place_type_t<_value_type> _, std::initializer_list<U> il,
|
||||
Args &&... args) noexcept(detail::is_nothrow_constructible<_value_type, std::initializer_list<U>, Args...>)
|
||||
: _state{_, il, static_cast<Args &&>(args)...}
|
||||
, _error()
|
||||
{
|
||||
}
|
||||
template <class... Args>
|
||||
constexpr explicit basic_result_storage(in_place_type_t<_error_type> /*unused*/, Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, Args...>)
|
||||
: _state{detail::status::have_error}
|
||||
, _error(static_cast<Args &&>(args)...)
|
||||
{
|
||||
_set_error_is_errno(_state, _error);
|
||||
}
|
||||
template <class U, class... Args>
|
||||
constexpr basic_result_storage(in_place_type_t<_error_type> /*unused*/, std::initializer_list<U> il, Args &&... args) noexcept(detail::is_nothrow_constructible<_error_type, std::initializer_list<U>, Args...>)
|
||||
: _state{detail::status::have_error}
|
||||
, _error{il, static_cast<Args &&>(args)...}
|
||||
{
|
||||
_set_error_is_errno(_state, _error);
|
||||
}
|
||||
struct compatible_conversion_tag
|
||||
{
|
||||
};
|
||||
template <class T, class U, class V>
|
||||
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
|
||||
: _state(o._state)
|
||||
, _error(o._error)
|
||||
{
|
||||
}
|
||||
template <class T, class V>
|
||||
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, const basic_result_storage<T, void, V> &o) noexcept(detail::is_nothrow_constructible<_value_type, T>)
|
||||
: _state(o._state)
|
||||
, _error(_error_type{})
|
||||
{
|
||||
}
|
||||
template <class T, class U, class V>
|
||||
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(detail::is_nothrow_constructible<_value_type, T> &&detail::is_nothrow_constructible<_error_type, U>)
|
||||
: _state(static_cast<decltype(o._state) &&>(o._state))
|
||||
, _error(static_cast<U &&>(o._error))
|
||||
{
|
||||
}
|
||||
template <class T, class V>
|
||||
constexpr basic_result_storage(compatible_conversion_tag /*unused*/, basic_result_storage<T, void, V> &&o) noexcept(detail::is_nothrow_constructible<_value_type, T>)
|
||||
: _state(static_cast<decltype(o._state) &&>(o._state))
|
||||
, _error(_error_type{})
|
||||
{
|
||||
}
|
||||
|
||||
struct make_error_code_compatible_conversion_tag
|
||||
{
|
||||
};
|
||||
template <class T, class U, class V>
|
||||
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
|
||||
: _state(o._state)
|
||||
, _error(make_error_code(o._error))
|
||||
{
|
||||
}
|
||||
template <class T, class U, class V>
|
||||
constexpr basic_result_storage(make_error_code_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_error_code(std::declval<U>())))
|
||||
: _state(static_cast<decltype(o._state) &&>(o._state))
|
||||
, _error(make_error_code(static_cast<U &&>(o._error)))
|
||||
{
|
||||
}
|
||||
|
||||
struct make_exception_ptr_compatible_conversion_tag
|
||||
{
|
||||
};
|
||||
template <class T, class U, class V>
|
||||
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, const basic_result_storage<T, U, V> &o) noexcept(detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
|
||||
: _state(o._state)
|
||||
, _error(make_exception_ptr(o._error))
|
||||
{
|
||||
}
|
||||
template <class T, class U, class V>
|
||||
constexpr basic_result_storage(make_exception_ptr_compatible_conversion_tag /*unused*/, basic_result_storage<T, U, V> &&o) noexcept(detail::is_nothrow_constructible<_value_type, T> &&noexcept(make_exception_ptr(std::declval<U>())))
|
||||
: _state(static_cast<decltype(o._state) &&>(o._state))
|
||||
, _error(make_exception_ptr(static_cast<U &&>(o._error)))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// Neither value nor error type can throw during swap
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
template <> struct basic_result_storage_swap<false, false>
|
||||
#else
|
||||
template <bool value_throws, bool error_throws> struct basic_result_storage_swap
|
||||
#endif
|
||||
{
|
||||
template <class R, class EC, class NoValuePolicy> constexpr basic_result_storage_swap(basic_result_storage<R, EC, NoValuePolicy> &a, basic_result_storage<R, EC, NoValuePolicy> &b)
|
||||
{
|
||||
using std::swap;
|
||||
a._msvc_nonpermissive_state().swap(b._msvc_nonpermissive_state());
|
||||
swap(a._msvc_nonpermissive_error(), b._msvc_nonpermissive_error());
|
||||
}
|
||||
};
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
// Swap potentially throwing value first
|
||||
template <> struct basic_result_storage_swap<true, false>
|
||||
{
|
||||
template <class R, class EC, class NoValuePolicy> constexpr basic_result_storage_swap(basic_result_storage<R, EC, NoValuePolicy> &a, basic_result_storage<R, EC, NoValuePolicy> &b)
|
||||
{
|
||||
using std::swap;
|
||||
a._msvc_nonpermissive_state().swap(b._msvc_nonpermissive_state());
|
||||
swap(a._msvc_nonpermissive_error(), b._msvc_nonpermissive_error());
|
||||
}
|
||||
};
|
||||
// Swap potentially throwing error first
|
||||
template <> struct basic_result_storage_swap<false, true>
|
||||
{
|
||||
template <class R, class EC, class NoValuePolicy> constexpr basic_result_storage_swap(basic_result_storage<R, EC, NoValuePolicy> &a, basic_result_storage<R, EC, NoValuePolicy> &b)
|
||||
{
|
||||
struct _
|
||||
{
|
||||
status_bitfield_type &a, &b;
|
||||
bool all_good{false};
|
||||
~_()
|
||||
{
|
||||
if(!all_good)
|
||||
{
|
||||
// We lost one of the values
|
||||
a.set_have_lost_consistency(true);
|
||||
b.set_have_lost_consistency(true);
|
||||
}
|
||||
}
|
||||
} _{a._msvc_nonpermissive_state()._status, b._msvc_nonpermissive_state()._status};
|
||||
strong_swap(_.all_good, a._msvc_nonpermissive_error(), b._msvc_nonpermissive_error());
|
||||
a._msvc_nonpermissive_state().swap(b._msvc_nonpermissive_state());
|
||||
}
|
||||
};
|
||||
// Both could throw
|
||||
template <> struct basic_result_storage_swap<true, true>
|
||||
{
|
||||
template <class R, class EC, class NoValuePolicy> basic_result_storage_swap(basic_result_storage<R, EC, NoValuePolicy> &a, basic_result_storage<R, EC, NoValuePolicy> &b)
|
||||
{
|
||||
using std::swap;
|
||||
// Swap value and status first, if it throws, status will remain unchanged
|
||||
a._msvc_nonpermissive_state().swap(b._msvc_nonpermissive_state());
|
||||
bool all_good = false;
|
||||
try
|
||||
{
|
||||
strong_swap(all_good, a._msvc_nonpermissive_error(), b._msvc_nonpermissive_error());
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
if(!all_good)
|
||||
{
|
||||
a._msvc_nonpermissive_state()._status.set_have_lost_consistency(true);
|
||||
b._msvc_nonpermissive_state()._status.set_have_lost_consistency(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We may still be able to rescue tis
|
||||
// First try to put the value and status back
|
||||
try
|
||||
{
|
||||
a._msvc_nonpermissive_state().swap(b._msvc_nonpermissive_state());
|
||||
// If that succeeded, continue by rethrowing the exception
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
all_good = false;
|
||||
}
|
||||
}
|
||||
if(!all_good)
|
||||
{
|
||||
// We are now trapped. The value swapped, the error did not,
|
||||
// trying to restore the value failed. We now have
|
||||
// inconsistent result objects. Best we can do is fix up the
|
||||
// status bits to prevent has_value() == has_error().
|
||||
auto check = [](basic_result_storage<R, EC, NoValuePolicy> &x) {
|
||||
bool has_value = x._state._status.have_value();
|
||||
bool has_error = x._state._status.have_error();
|
||||
bool has_exception = x._state._status.have_exception();
|
||||
x._state._status.set_have_lost_consistency(true);
|
||||
if(has_value == (has_error || has_exception))
|
||||
{
|
||||
if(has_value)
|
||||
{
|
||||
// We know the value swapped and is now set, so clear error and exception
|
||||
x._state._status.set_have_error(false).set_have_exception(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We know the value swapped and is now unset, so set error
|
||||
x._state._status.set_have_error(true);
|
||||
// TODO: Should I default construct reset _error? It's guaranteed default constructible.
|
||||
}
|
||||
}
|
||||
};
|
||||
check(a);
|
||||
check(b);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/* Value observers for a very simple basic_result type
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (2 commits)
|
||||
File Created: Oct 2017
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_RESULT_VALUE_OBSERVERS_HPP
|
||||
#define BOOST_OUTCOME_RESULT_VALUE_OBSERVERS_HPP
|
||||
|
||||
#include "basic_result_storage.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Base, class R, class NoValuePolicy> class basic_result_value_observers : public Base
|
||||
{
|
||||
public:
|
||||
using value_type = R;
|
||||
using Base::Base;
|
||||
|
||||
constexpr value_type &assume_value() & noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &>(*this));
|
||||
return this->_state._value; // NOLINT
|
||||
}
|
||||
constexpr const value_type &assume_value() const &noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &>(*this));
|
||||
return this->_state._value; // NOLINT
|
||||
}
|
||||
constexpr value_type &&assume_value() && noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_value_check(static_cast<basic_result_value_observers &&>(*this));
|
||||
return static_cast<value_type &&>(this->_state._value); // NOLINT
|
||||
}
|
||||
constexpr const value_type &&assume_value() const &&noexcept
|
||||
{
|
||||
NoValuePolicy::narrow_value_check(static_cast<const basic_result_value_observers &&>(*this));
|
||||
return static_cast<const value_type &&>(this->_state._value); // NOLINT
|
||||
}
|
||||
|
||||
constexpr value_type &value() &
|
||||
{
|
||||
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &>(*this));
|
||||
return this->_state._value; // NOLINT
|
||||
}
|
||||
constexpr const value_type &value() const &
|
||||
{
|
||||
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &>(*this));
|
||||
return this->_state._value; // NOLINT
|
||||
}
|
||||
constexpr value_type &&value() &&
|
||||
{
|
||||
NoValuePolicy::wide_value_check(static_cast<basic_result_value_observers &&>(*this));
|
||||
return static_cast<value_type &&>(this->_state._value); // NOLINT
|
||||
}
|
||||
constexpr const value_type &&value() const &&
|
||||
{
|
||||
NoValuePolicy::wide_value_check(static_cast<const basic_result_value_observers &&>(*this));
|
||||
return static_cast<const value_type &&>(this->_state._value); // NOLINT
|
||||
}
|
||||
};
|
||||
template <class Base, class NoValuePolicy> class basic_result_value_observers<Base, void, NoValuePolicy> : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base;
|
||||
|
||||
constexpr void assume_value() const noexcept { NoValuePolicy::narrow_value_check(*this); }
|
||||
constexpr void value() const { NoValuePolicy::wide_value_check(*this); }
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,389 @@
|
||||
/* Tells C++ coroutines about Outcome's result
|
||||
(C) 2019-2020 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
|
||||
File Created: Oct 2019
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_COROUTINE_SUPPORT_NAMESPACE_BEGIN
|
||||
#error This header must only be included by outcome/coroutine_support.hpp or outcome/experimental/coroutine_support.hpp
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_OUTCOME_DETAIL_COROUTINE_SUPPORT_HPP
|
||||
#define BOOST_OUTCOME_DETAIL_COROUTINE_SUPPORT_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
|
||||
#if __cpp_impl_coroutine || (defined(_MSC_VER) && __cpp_coroutines) || (defined(__clang__) && __cpp_coroutines)
|
||||
#ifndef BOOST_OUTCOME_HAVE_NOOP_COROUTINE
|
||||
#if defined(__has_builtin)
|
||||
#if __has_builtin(__builtin_coro_noop)
|
||||
#define BOOST_OUTCOME_HAVE_NOOP_COROUTINE 1
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifndef BOOST_OUTCOME_HAVE_NOOP_COROUTINE
|
||||
#if _MSC_VER >= 1928
|
||||
#define BOOST_OUTCOME_HAVE_NOOP_COROUTINE 1
|
||||
#else
|
||||
#define BOOST_OUTCOME_HAVE_NOOP_COROUTINE 0
|
||||
#endif
|
||||
#endif
|
||||
#if __has_include(<coroutine>)
|
||||
#include <coroutine>
|
||||
BOOST_OUTCOME_V2_NAMESPACE_BEGIN
|
||||
namespace awaitables
|
||||
{
|
||||
template <class Promise = void> using coroutine_handle = std::coroutine_handle<Promise>;
|
||||
template <class... Args> using coroutine_traits = std::coroutine_traits<Args...>;
|
||||
using std::suspend_always;
|
||||
using std::suspend_never;
|
||||
#if BOOST_OUTCOME_HAVE_NOOP_COROUTINE
|
||||
using std::noop_coroutine;
|
||||
#endif
|
||||
} // namespace awaitables
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
#define BOOST_OUTCOME_FOUND_COROUTINE_HEADER 1
|
||||
#elif __has_include(<experimental/coroutine>)
|
||||
#include <experimental/coroutine>
|
||||
BOOST_OUTCOME_V2_NAMESPACE_BEGIN
|
||||
namespace awaitables
|
||||
{
|
||||
template <class Promise = void> using coroutine_handle = std::experimental::coroutine_handle<Promise>;
|
||||
template <class... Args> using coroutine_traits = std::experimental::coroutine_traits<Args...>;
|
||||
using std::experimental::suspend_always;
|
||||
using std::experimental::suspend_never;
|
||||
#if BOOST_OUTCOME_HAVE_NOOP_COROUTINE
|
||||
using std::experimental::noop_coroutine;
|
||||
#endif
|
||||
} // namespace awaitables
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
#define BOOST_OUTCOME_FOUND_COROUTINE_HEADER 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
|
||||
namespace awaitables
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct error_type_not_found
|
||||
{
|
||||
};
|
||||
struct exception_type_not_found
|
||||
{
|
||||
};
|
||||
template <class T> struct type_found
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
template <class T, class U = typename T::error_type> constexpr inline type_found<U> extract_error_type(int /*unused*/) { return {}; }
|
||||
template <class T> constexpr inline type_found<error_type_not_found> extract_error_type(...) { return {}; }
|
||||
template <class T, class U = typename T::exception_type> constexpr inline type_found<U> extract_exception_type(int /*unused*/) { return {}; }
|
||||
template <class T> constexpr inline type_found<exception_type_not_found> extract_exception_type(...) { return {}; }
|
||||
|
||||
BOOST_OUTCOME_TEMPLATE(class T, class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(BOOST_OUTCOME_V2_NAMESPACE::detail::is_constructible<U, T>))
|
||||
inline bool try_set_error(T &&e, U *result)
|
||||
{
|
||||
new(result) U(static_cast<T &&>(e));
|
||||
return true;
|
||||
}
|
||||
template <class T> inline bool try_set_error(T && /*unused*/, ...) { return false; }
|
||||
BOOST_OUTCOME_TEMPLATE(class T, class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(BOOST_OUTCOME_V2_NAMESPACE::detail::is_constructible<U, T>))
|
||||
inline void set_or_rethrow(T &e, U *result) { new(result) U(e); }
|
||||
template <class T> inline void set_or_rethrow(T &e, ...) { rethrow_exception(e); }
|
||||
template <class T> class fake_atomic
|
||||
{
|
||||
T _v;
|
||||
|
||||
public:
|
||||
constexpr fake_atomic(T v)
|
||||
: _v(v)
|
||||
{
|
||||
}
|
||||
T load(std::memory_order /*unused*/) { return _v; }
|
||||
void store(T v, std::memory_order /*unused*/) { _v = v; }
|
||||
};
|
||||
|
||||
#ifdef BOOST_OUTCOME_FOUND_COROUTINE_HEADER
|
||||
template <class Awaitable, bool suspend_initial, bool use_atomic, bool is_void> struct outcome_promise_type
|
||||
{
|
||||
using container_type = typename Awaitable::container_type;
|
||||
using result_set_type = std::conditional_t<use_atomic, std::atomic<bool>, fake_atomic<bool>>;
|
||||
union
|
||||
{
|
||||
BOOST_OUTCOME_V2_NAMESPACE::detail::empty_type _default{};
|
||||
container_type result;
|
||||
};
|
||||
result_set_type result_set{false};
|
||||
coroutine_handle<> continuation;
|
||||
|
||||
outcome_promise_type() noexcept {}
|
||||
outcome_promise_type(const outcome_promise_type &) = delete;
|
||||
outcome_promise_type(outcome_promise_type &&) = delete;
|
||||
outcome_promise_type &operator=(const outcome_promise_type &) = delete;
|
||||
outcome_promise_type &operator=(outcome_promise_type &&) = delete;
|
||||
~outcome_promise_type()
|
||||
{
|
||||
if(result_set.load(std::memory_order_acquire))
|
||||
{
|
||||
result.~container_type(); // could throw
|
||||
}
|
||||
}
|
||||
auto get_return_object()
|
||||
{
|
||||
return Awaitable{*this}; // could throw bad_alloc
|
||||
}
|
||||
void return_value(container_type &&value)
|
||||
{
|
||||
assert(!result_set.load(std::memory_order_acquire));
|
||||
if(result_set.load(std::memory_order_acquire))
|
||||
{
|
||||
result.~container_type(); // could throw
|
||||
}
|
||||
new(&result) container_type(static_cast<container_type &&>(value)); // could throw
|
||||
result_set.store(true, std::memory_order_release);
|
||||
}
|
||||
void return_value(const container_type &value)
|
||||
{
|
||||
assert(!result_set.load(std::memory_order_acquire));
|
||||
if(result_set.load(std::memory_order_acquire))
|
||||
{
|
||||
result.~container_type(); // could throw
|
||||
}
|
||||
new(&result) container_type(value); // could throw
|
||||
result_set.store(true, std::memory_order_release);
|
||||
}
|
||||
void unhandled_exception()
|
||||
{
|
||||
assert(!result_set.load(std::memory_order_acquire));
|
||||
if(result_set.load(std::memory_order_acquire))
|
||||
{
|
||||
result.~container_type();
|
||||
}
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
auto e = std::current_exception();
|
||||
auto ec = detail::error_from_exception(static_cast<decltype(e) &&>(e), {});
|
||||
// Try to set error code first
|
||||
if(!detail::error_is_set(ec) || !detail::try_set_error(static_cast<decltype(ec) &&>(ec), &result))
|
||||
{
|
||||
detail::set_or_rethrow(e, &result); // could throw
|
||||
}
|
||||
#else
|
||||
std::terminate();
|
||||
#endif
|
||||
result_set.store(true, std::memory_order_release);
|
||||
}
|
||||
auto initial_suspend() noexcept
|
||||
{
|
||||
struct awaiter
|
||||
{
|
||||
bool await_ready() noexcept { return !suspend_initial; }
|
||||
void await_resume() noexcept {}
|
||||
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
|
||||
};
|
||||
return awaiter{};
|
||||
}
|
||||
auto final_suspend() noexcept
|
||||
{
|
||||
struct awaiter
|
||||
{
|
||||
bool await_ready() noexcept { return false; }
|
||||
void await_resume() noexcept {}
|
||||
#if BOOST_OUTCOME_HAVE_NOOP_COROUTINE
|
||||
coroutine_handle<> await_suspend(coroutine_handle<outcome_promise_type> self) noexcept
|
||||
{
|
||||
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
|
||||
}
|
||||
#else
|
||||
void await_suspend(coroutine_handle<outcome_promise_type> self)
|
||||
{
|
||||
if(self.promise().continuation)
|
||||
{
|
||||
return self.promise().continuation.resume();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
return awaiter{};
|
||||
}
|
||||
};
|
||||
template <class Awaitable, bool suspend_initial, bool use_atomic> struct outcome_promise_type<Awaitable, suspend_initial, use_atomic, true>
|
||||
{
|
||||
using container_type = void;
|
||||
using result_set_type = std::conditional_t<use_atomic, std::atomic<bool>, fake_atomic<bool>>;
|
||||
result_set_type result_set{false};
|
||||
coroutine_handle<> continuation;
|
||||
|
||||
outcome_promise_type() {}
|
||||
outcome_promise_type(const outcome_promise_type &) = delete;
|
||||
outcome_promise_type(outcome_promise_type &&) = delete;
|
||||
outcome_promise_type &operator=(const outcome_promise_type &) = delete;
|
||||
outcome_promise_type &operator=(outcome_promise_type &&) = delete;
|
||||
~outcome_promise_type() = default;
|
||||
auto get_return_object()
|
||||
{
|
||||
return Awaitable{*this}; // could throw bad_alloc
|
||||
}
|
||||
void return_void() noexcept
|
||||
{
|
||||
assert(!result_set.load(std::memory_order_acquire));
|
||||
result_set.store(true, std::memory_order_release);
|
||||
}
|
||||
void unhandled_exception()
|
||||
{
|
||||
assert(!result_set.load(std::memory_order_acquire));
|
||||
std::rethrow_exception(std::current_exception()); // throws
|
||||
}
|
||||
auto initial_suspend() noexcept
|
||||
{
|
||||
struct awaiter
|
||||
{
|
||||
bool await_ready() noexcept { return !suspend_initial; }
|
||||
void await_resume() noexcept {}
|
||||
void await_suspend(coroutine_handle<> /*unused*/) noexcept {}
|
||||
};
|
||||
return awaiter{};
|
||||
}
|
||||
auto final_suspend() noexcept
|
||||
{
|
||||
struct awaiter
|
||||
{
|
||||
bool await_ready() noexcept { return false; }
|
||||
void await_resume() noexcept {}
|
||||
#if BOOST_OUTCOME_HAVE_NOOP_COROUTINE
|
||||
coroutine_handle<> await_suspend(coroutine_handle<outcome_promise_type> self) noexcept
|
||||
{
|
||||
return self.promise().continuation ? self.promise().continuation : noop_coroutine();
|
||||
}
|
||||
#else
|
||||
void await_suspend(coroutine_handle<outcome_promise_type> self)
|
||||
{
|
||||
if(self.promise().continuation)
|
||||
{
|
||||
return self.promise().continuation.resume();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
return awaiter{};
|
||||
}
|
||||
};
|
||||
template <class Awaitable, bool suspend_initial, bool use_atomic>
|
||||
constexpr inline auto move_result_from_promise_if_not_void(outcome_promise_type<Awaitable, suspend_initial, use_atomic, false> &p)
|
||||
{
|
||||
return static_cast<typename Awaitable::container_type &&>(p.result);
|
||||
}
|
||||
template <class Awaitable, bool suspend_initial, bool use_atomic>
|
||||
constexpr inline void move_result_from_promise_if_not_void(outcome_promise_type<Awaitable, suspend_initial, use_atomic, true> & /*unused*/)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Cont, bool suspend_initial, bool use_atomic> struct BOOST_OUTCOME_NODISCARD awaitable
|
||||
{
|
||||
using container_type = Cont;
|
||||
using promise_type = outcome_promise_type<awaitable, suspend_initial, use_atomic, std::is_void<container_type>::value>;
|
||||
coroutine_handle<promise_type> _h;
|
||||
|
||||
awaitable(awaitable &&o) noexcept
|
||||
: _h(static_cast<coroutine_handle<promise_type> &&>(o._h))
|
||||
{
|
||||
o._h = nullptr;
|
||||
}
|
||||
awaitable(const awaitable &o) = delete;
|
||||
awaitable &operator=(awaitable &&) = delete; // as per P1056
|
||||
awaitable &operator=(const awaitable &) = delete;
|
||||
~awaitable()
|
||||
{
|
||||
if(_h)
|
||||
{
|
||||
_h.destroy();
|
||||
}
|
||||
}
|
||||
explicit awaitable(promise_type &p) // could throw
|
||||
: _h(coroutine_handle<promise_type>::from_promise(p))
|
||||
{
|
||||
}
|
||||
bool await_ready() noexcept { return _h.promise().result_set.load(std::memory_order_acquire); }
|
||||
container_type await_resume()
|
||||
{
|
||||
assert(_h.promise().result_set.load(std::memory_order_acquire));
|
||||
if(!_h.promise().result_set.load(std::memory_order_acquire))
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
return detail::move_result_from_promise_if_not_void(_h.promise());
|
||||
}
|
||||
#if BOOST_OUTCOME_HAVE_NOOP_COROUTINE
|
||||
coroutine_handle<> await_suspend(coroutine_handle<> cont) noexcept
|
||||
{
|
||||
_h.promise().continuation = cont;
|
||||
return _h;
|
||||
}
|
||||
#else
|
||||
void await_suspend(coroutine_handle<> cont)
|
||||
{
|
||||
_h.promise().continuation = cont;
|
||||
_h.resume();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
} // namespace detail
|
||||
|
||||
} // namespace awaitables
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_OUTCOME_FOUND_COROUTINE_HEADER
|
||||
BOOST_OUTCOME_COROUTINE_SUPPORT_NAMESPACE_EXPORT_BEGIN
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL
|
||||
SIGNATURE NOT RECOGNISED
|
||||
*/
|
||||
template <class T> using eager = BOOST_OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, false, false>;
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL
|
||||
SIGNATURE NOT RECOGNISED
|
||||
*/
|
||||
template <class T> using atomic_eager = BOOST_OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, false, true>;
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL
|
||||
SIGNATURE NOT RECOGNISED
|
||||
*/
|
||||
template <class T> using lazy = BOOST_OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, true, false>;
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL
|
||||
SIGNATURE NOT RECOGNISED
|
||||
*/
|
||||
template <class T> using atomic_lazy = BOOST_OUTCOME_V2_NAMESPACE::awaitables::detail::awaitable<T, true, true>;
|
||||
|
||||
BOOST_OUTCOME_COROUTINE_SUPPORT_NAMESPACE_END
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/* UPDATED BY SCRIPT
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (225 commits)
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
|
||||
#define BOOST_OUTCOME_PREVIOUS_COMMIT_REF a853fc09bb9590204a33c62bd3fd32f9b212c69f
|
||||
#define BOOST_OUTCOME_PREVIOUS_COMMIT_DATE "2020-10-09 09:46:07 +00:00"
|
||||
#define BOOST_OUTCOME_PREVIOUS_COMMIT_UNIQUE a853fc09
|
||||
@@ -0,0 +1,129 @@
|
||||
/* Traits for Outcome
|
||||
(C) 2018-2020 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
|
||||
File Created: March 2018
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
|
||||
#define BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#include <system_error>
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// Customise _set_error_is_errno
|
||||
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_code &error)
|
||||
{
|
||||
if(error.category() == std::generic_category()
|
||||
#ifndef _WIN32
|
||||
|| error.category() == std::system_category()
|
||||
#endif
|
||||
)
|
||||
{
|
||||
state._status.set_have_error_is_errno(true);
|
||||
}
|
||||
}
|
||||
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_condition &error)
|
||||
{
|
||||
if(error.category() == std::generic_category()
|
||||
#ifndef _WIN32
|
||||
|| error.category() == std::system_category()
|
||||
#endif
|
||||
)
|
||||
{
|
||||
state._status.set_have_error_is_errno(true);
|
||||
}
|
||||
}
|
||||
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & /*unused*/) {
|
||||
state._status.set_have_error_is_errno(true);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
namespace policy
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
/* Pass through `make_error_code` function for `std::error_code`.
|
||||
*/
|
||||
inline std::error_code make_error_code(std::error_code v) { return v; }
|
||||
|
||||
// Try ADL, if not use fall backs above
|
||||
template <class T> constexpr inline decltype(auto) error_code(T &&v) { return make_error_code(std::forward<T>(v)); }
|
||||
|
||||
struct std_enum_overload_tag
|
||||
{
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL
|
||||
SIGNATURE NOT RECOGNISED
|
||||
*/
|
||||
template <class T> constexpr inline decltype(auto) error_code(T &&v) { return detail::error_code(std::forward<T>(v)); }
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL
|
||||
SIGNATURE NOT RECOGNISED
|
||||
*/
|
||||
// inline void outcome_throw_as_system_error_with_payload(...) = delete; // To use the error_code_throw_as_system_error policy with a custom Error type, you must define a outcome_throw_as_system_error_with_payload() free function to say how to handle the payload
|
||||
inline void outcome_throw_as_system_error_with_payload(const std::error_code &error) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(error)); } // NOLINT
|
||||
BOOST_OUTCOME_TEMPLATE(class Error)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_error_code_enum<std::decay_t<Error>>::value || std::is_error_condition_enum<std::decay_t<Error>>::value))
|
||||
inline void outcome_throw_as_system_error_with_payload(Error &&error, detail::std_enum_overload_tag /*unused*/ = detail::std_enum_overload_tag()) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(make_error_code(error))); } // NOLINT
|
||||
} // namespace policy
|
||||
|
||||
namespace trait
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <> struct _is_error_code_available<std::error_code>
|
||||
{
|
||||
// Shortcut this for lower build impact
|
||||
static constexpr bool value = true;
|
||||
using type = std::error_code;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
// std::error_code is an error type
|
||||
template <> struct is_error_type<std::error_code>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
// For std::error_code, std::is_error_condition_enum<> is the trait we want.
|
||||
template <class Enum> struct is_error_type_enum<std::error_code, Enum>
|
||||
{
|
||||
static constexpr bool value = std::is_error_condition_enum<Enum>::value;
|
||||
};
|
||||
|
||||
} // namespace trait
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
/* Traits for Outcome
|
||||
(C) 2018-2020 Niall Douglas <http://www.nedproductions.biz/> (3 commits)
|
||||
File Created: March 2018
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_OUTCOME_TRAIT_STD_EXCEPTION_HPP
|
||||
#define BOOST_OUTCOME_TRAIT_STD_EXCEPTION_HPP
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#include <exception>
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_BEGIN
|
||||
|
||||
namespace policy
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
/* Pass through `make_exception_ptr` function for `std::exception_ptr`.
|
||||
*/
|
||||
inline std::exception_ptr make_exception_ptr(std::exception_ptr v) { return v; }
|
||||
|
||||
// Try ADL, if not use fall backs above
|
||||
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return make_exception_ptr(std::forward<T>(v)); }
|
||||
} // namespace detail
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL
|
||||
SIGNATURE NOT RECOGNISED
|
||||
*/
|
||||
template <class T> constexpr inline decltype(auto) exception_ptr(T &&v) { return detail::exception_ptr(std::forward<T>(v)); }
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool has_error_payload> struct _rethrow_exception
|
||||
{
|
||||
template <class Exception> explicit _rethrow_exception(Exception && /*unused*/) // NOLINT
|
||||
{
|
||||
}
|
||||
};
|
||||
template <> struct _rethrow_exception<true>
|
||||
{
|
||||
template <class Exception> explicit _rethrow_exception(Exception &&excpt) // NOLINT
|
||||
{
|
||||
// ADL
|
||||
rethrow_exception(policy::exception_ptr(std::forward<Exception>(excpt)));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace policy
|
||||
|
||||
namespace trait
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
// Shortcut this for lower build impact
|
||||
template <> struct _is_exception_ptr_available<std::exception_ptr>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
using type = std::exception_ptr;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
// std::exception_ptr is an error type
|
||||
template <> struct is_error_type<std::exception_ptr>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
} // namespace trait
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
1086
install/boost_1_75_0/include/boost/outcome/detail/value_storage.hpp
Normal file
1086
install/boost_1_75_0/include/boost/outcome/detail/value_storage.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
/* Sets Outcome version
|
||||
(C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (4 commits)
|
||||
|
||||
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL */
|
||||
#define BOOST_OUTCOME_VERSION_MAJOR 2
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL */
|
||||
#define BOOST_OUTCOME_VERSION_MINOR 1
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL */
|
||||
#define BOOST_OUTCOME_VERSION_PATCH 0
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL */
|
||||
#define BOOST_OUTCOME_VERSION_REVISION 0 // Revision version for cmake and DLL version stamping
|
||||
|
||||
/*! AWAITING HUGO JSON CONVERSION TOOL */
|
||||
#ifndef BOOST_OUTCOME_DISABLE_ABI_PERMUTATION
|
||||
#define BOOST_OUTCOME_UNSTABLE_VERSION
|
||||
#endif
|
||||
Reference in New Issue
Block a user