add boost on mac
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/* Exception observers for outcome type
|
||||
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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
|
||||
{
|
||||
};
|
||||
BOOST_OUTCOME_TEMPLATE(class S) //
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(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 <= 1920 // 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 & detail::status_have_exception) != 0)
|
||||
{
|
||||
return this->assume_exception();
|
||||
}
|
||||
if((this->_state._status & detail::status_have_error) != 0)
|
||||
{
|
||||
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-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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
|
||||
157
macx64/include/boost/outcome/detail/basic_result_final.hpp
Normal file
157
macx64/include/boost/outcome/detail/basic_result_final.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/* Finaliser for a very simple result type
|
||||
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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 & detail::status_have_value) != 0; }
|
||||
constexpr bool has_value() const noexcept { return (this->_state._status & detail::status_have_value) != 0; }
|
||||
constexpr bool has_error() const noexcept { return (this->_state._status & detail::status_have_error) != 0; }
|
||||
constexpr bool has_exception() const noexcept { return (this->_state._status & detail::status_have_exception) != 0; }
|
||||
constexpr bool has_failure() const noexcept { return (this->_state._status & detail::status_have_error) != 0 || (this->_state._status & detail::status_have_exception) != 0; }
|
||||
|
||||
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 & detail::status_have_value) != 0 && (o._state._status & detail::status_have_value) != 0)
|
||||
{
|
||||
return this->_state._value == o._state._value; // NOLINT
|
||||
}
|
||||
if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0)
|
||||
{
|
||||
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 & detail::status_have_value) != 0)
|
||||
{
|
||||
return this->_state._value == o.value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
constexpr bool operator==(const success_type<void> &o) const noexcept
|
||||
{
|
||||
(void) o;
|
||||
return (this->_state._status & detail::status_have_value) != 0;
|
||||
}
|
||||
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 & detail::status_have_error) != 0)
|
||||
{
|
||||
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 & detail::status_have_value) != 0 && (o._state._status & detail::status_have_value) != 0)
|
||||
{
|
||||
return this->_state._value != o._state._value;
|
||||
}
|
||||
if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0)
|
||||
{
|
||||
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 & detail::status_have_value) != 0)
|
||||
{
|
||||
return this->_state._value != o.value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
constexpr bool operator!=(const success_type<void> &o) const noexcept
|
||||
{
|
||||
(void) o;
|
||||
return (this->_state._status & detail::status_have_value) == 0;
|
||||
}
|
||||
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 & detail::status_have_error) != 0)
|
||||
{
|
||||
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
|
||||
257
macx64/include/boost/outcome/detail/basic_result_storage.hpp
Normal file
257
macx64/include/boost/outcome/detail/basic_result_storage.hpp
Normal file
@@ -0,0 +1,257 @@
|
||||
/* Storage for a very simple basic_result type
|
||||
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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 S, class NoValuePolicy> class basic_result_final;
|
||||
} // namespace detail
|
||||
|
||||
namespace hooks
|
||||
{
|
||||
template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_final<R, S, NoValuePolicy> *r) noexcept;
|
||||
template <class R, class S, class NoValuePolicy> constexpr inline void set_spare_storage(detail::basic_result_final<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> //
|
||||
BOOST_OUTCOME_REQUIRES(trait::type_can_be_used_in_basic_result<R> &&trait::type_can_be_used_in_basic_result<EC> && (std::is_void<EC>::value || std::is_default_constructible<EC>::value)) //
|
||||
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_final<T, U, V> *r) noexcept; // NOLINT
|
||||
template <class T, class U, class V> friend constexpr inline void hooks::set_spare_storage(detail::basic_result_final<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>;
|
||||
|
||||
#ifdef BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE
|
||||
detail::value_storage_trivial<_value_type> _state;
|
||||
#else
|
||||
detail::value_storage_select_impl<_value_type> _state;
|
||||
#endif
|
||||
detail::devoid<_error_type> _error;
|
||||
|
||||
public:
|
||||
// Used by iostream support to access state
|
||||
detail::value_storage_select_impl<_value_type> &_iostreams_state() { return _state; }
|
||||
const detail::value_storage_select_impl<_value_type> &_iostreams_state() const { return _state; }
|
||||
|
||||
// Hack to work around MSVC bug in /permissive-
|
||||
detail::value_storage_select_impl<_value_type> &_msvc_nonpermissive_state() { return _state; }
|
||||
detail::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(std::is_nothrow_constructible<_value_type, Args...>::value)
|
||||
: _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(std::is_nothrow_constructible<_value_type, std::initializer_list<U>, Args...>::value)
|
||||
: _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(std::is_nothrow_constructible<_error_type, Args...>::value)
|
||||
: _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(std::is_nothrow_constructible<_error_type, std::initializer_list<U>, Args...>::value)
|
||||
: _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(std::is_nothrow_constructible<_value_type, T>::value &&std::is_nothrow_constructible<_error_type, U>::value)
|
||||
: _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(std::is_nothrow_constructible<_value_type, T>::value)
|
||||
: _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(std::is_nothrow_constructible<_value_type, T>::value &&std::is_nothrow_constructible<_error_type, U>::value)
|
||||
: _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(std::is_nothrow_constructible<_value_type, T>::value)
|
||||
: _state(static_cast<decltype(o._state) &&>(o._state))
|
||||
, _error(_error_type{})
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// 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)
|
||||
{
|
||||
using std::swap;
|
||||
swap(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());
|
||||
try
|
||||
{
|
||||
swap(a._msvc_nonpermissive_error(), b._msvc_nonpermissive_error());
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// 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(...)
|
||||
{
|
||||
// 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 & detail::status_have_value) != 0;
|
||||
bool has_error = (x._state._status & detail::status_have_error) != 0;
|
||||
bool has_exception = (x._state._status & detail::status_have_exception) != 0;
|
||||
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 &= ~(detail::status_have_error | detail::status_have_exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We know the value swapped and is now unset, so set error
|
||||
x._state._status |= detail::status_have_error;
|
||||
// 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-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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
|
||||
126
macx64/include/boost/outcome/detail/trait_std_error_code.hpp
Normal file
126
macx64/include/boost/outcome/detail/trait_std_error_code.hpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/* Traits for Outcome
|
||||
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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 |= status_error_is_errno;
|
||||
}
|
||||
}
|
||||
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 |= status_error_is_errno;
|
||||
}
|
||||
}
|
||||
template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & /*unused*/) { state._status |= status_error_is_errno; }
|
||||
|
||||
} // 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;
|
||||
};
|
||||
} // 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
|
||||
97
macx64/include/boost/outcome/detail/trait_std_exception.hpp
Normal file
97
macx64/include/boost/outcome/detail/trait_std_exception.hpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/* Traits for Outcome
|
||||
(C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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;
|
||||
};
|
||||
} // 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
|
||||
364
macx64/include/boost/outcome/detail/value_storage.hpp
Normal file
364
macx64/include/boost/outcome/detail/value_storage.hpp
Normal file
@@ -0,0 +1,364 @@
|
||||
/* Essentially an internal optional implementation :)
|
||||
(C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (59 commits)
|
||||
File Created: June 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_VALUE_STORAGE_HPP
|
||||
#define BOOST_OUTCOME_VALUE_STORAGE_HPP
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_BEGIN
|
||||
|
||||
namespace detail
|
||||
{
|
||||
using status_bitfield_type = uint32_t;
|
||||
|
||||
// WARNING: These bits are not tracked by abi-dumper, but changing them will break ABI!
|
||||
static constexpr status_bitfield_type status_have_value = (1U << 0U);
|
||||
static constexpr status_bitfield_type status_have_error = (1U << 1U);
|
||||
static constexpr status_bitfield_type status_have_exception = (1U << 2U);
|
||||
static constexpr status_bitfield_type status_error_is_errno = (1U << 4U); // can errno be set from this error?
|
||||
// bit 7 unused
|
||||
// bits 8-15 unused
|
||||
// bits 16-31 used for user supplied 16 bit value
|
||||
static constexpr status_bitfield_type status_2byte_shift = 16;
|
||||
static constexpr status_bitfield_type status_2byte_mask = (0xffffU << status_2byte_shift);
|
||||
|
||||
// Used if T is trivial
|
||||
template <class T> struct value_storage_trivial
|
||||
{
|
||||
using value_type = T;
|
||||
union {
|
||||
empty_type _empty;
|
||||
devoid<T> _value;
|
||||
};
|
||||
status_bitfield_type _status{0};
|
||||
constexpr value_storage_trivial() noexcept : _empty{} {}
|
||||
// Special from-void catchall constructor, always constructs default T irrespective of whether void is valued or not (can do no better if T cannot be copied)
|
||||
struct disable_void_catchall
|
||||
{
|
||||
};
|
||||
using void_value_storage_trivial = std::conditional_t<std::is_void<T>::value, disable_void_catchall, value_storage_trivial<void>>;
|
||||
explicit constexpr value_storage_trivial(const void_value_storage_trivial &o) noexcept(std::is_nothrow_default_constructible<value_type>::value)
|
||||
: _value()
|
||||
, _status(o._status)
|
||||
{
|
||||
}
|
||||
value_storage_trivial(const value_storage_trivial &) = default; // NOLINT
|
||||
value_storage_trivial(value_storage_trivial &&) = default; // NOLINT
|
||||
value_storage_trivial &operator=(const value_storage_trivial &) = default; // NOLINT
|
||||
value_storage_trivial &operator=(value_storage_trivial &&) = default; // NOLINT
|
||||
~value_storage_trivial() = default;
|
||||
constexpr explicit value_storage_trivial(status_bitfield_type status)
|
||||
: _empty()
|
||||
, _status(status)
|
||||
{
|
||||
}
|
||||
template <class... Args>
|
||||
constexpr explicit value_storage_trivial(in_place_type_t<value_type> /*unused*/, Args &&... args) noexcept(std::is_nothrow_constructible<value_type, Args...>::value)
|
||||
: _value(static_cast<Args &&>(args)...)
|
||||
, _status(status_have_value)
|
||||
{
|
||||
}
|
||||
template <class U, class... Args>
|
||||
constexpr value_storage_trivial(in_place_type_t<value_type> /*unused*/, std::initializer_list<U> il, Args &&... args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>::value)
|
||||
: _value(il, static_cast<Args &&>(args)...)
|
||||
, _status(status_have_value)
|
||||
{
|
||||
}
|
||||
template <class U> static constexpr bool enable_converting_constructor = !std::is_same<std::decay_t<U>, value_type>::value && std::is_constructible<value_type, U>::value;
|
||||
BOOST_OUTCOME_TEMPLATE(class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(enable_converting_constructor<U>))
|
||||
constexpr explicit value_storage_trivial(const value_storage_trivial<U> &o) noexcept(std::is_nothrow_constructible<value_type, U>::value)
|
||||
: value_storage_trivial(((o._status & status_have_value) != 0) ? value_storage_trivial(in_place_type<value_type>, o._value) : value_storage_trivial()) // NOLINT
|
||||
{
|
||||
_status = o._status;
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(enable_converting_constructor<U>))
|
||||
constexpr explicit value_storage_trivial(value_storage_trivial<U> &&o) noexcept(std::is_nothrow_constructible<value_type, U>::value)
|
||||
: value_storage_trivial(((o._status & status_have_value) != 0) ? value_storage_trivial(in_place_type<value_type>, static_cast<U &&>(o._value)) : value_storage_trivial()) // NOLINT
|
||||
{
|
||||
_status = o._status;
|
||||
}
|
||||
constexpr void swap(value_storage_trivial &o) noexcept
|
||||
{
|
||||
// storage is trivial, so just use assignment
|
||||
auto temp = static_cast<value_storage_trivial &&>(*this);
|
||||
*this = static_cast<value_storage_trivial &&>(o);
|
||||
o = static_cast<value_storage_trivial &&>(temp);
|
||||
}
|
||||
};
|
||||
// Used if T is non-trivial
|
||||
template <class T> struct value_storage_nontrivial
|
||||
{
|
||||
using value_type = T;
|
||||
union {
|
||||
empty_type _empty;
|
||||
value_type _value;
|
||||
};
|
||||
status_bitfield_type _status{0};
|
||||
value_storage_nontrivial() noexcept : _empty{} {}
|
||||
value_storage_nontrivial &operator=(const value_storage_nontrivial &) = default; // if reaches here, copy assignment is trivial
|
||||
value_storage_nontrivial &operator=(value_storage_nontrivial &&) = default; // NOLINT if reaches here, move assignment is trivial
|
||||
value_storage_nontrivial(value_storage_nontrivial &&o) noexcept(std::is_nothrow_move_constructible<value_type>::value) // NOLINT
|
||||
: _status(o._status)
|
||||
{
|
||||
if(this->_status & status_have_value)
|
||||
{
|
||||
this->_status &= ~status_have_value;
|
||||
new(&_value) value_type(static_cast<value_type &&>(o._value)); // NOLINT
|
||||
_status = o._status;
|
||||
}
|
||||
}
|
||||
value_storage_nontrivial(const value_storage_nontrivial &o) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
|
||||
: _status(o._status)
|
||||
{
|
||||
if(this->_status & status_have_value)
|
||||
{
|
||||
this->_status &= ~status_have_value;
|
||||
new(&_value) value_type(o._value); // NOLINT
|
||||
_status = o._status;
|
||||
}
|
||||
}
|
||||
// Special from-void constructor, constructs default T if void valued
|
||||
explicit value_storage_nontrivial(const value_storage_trivial<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value)
|
||||
: _status(o._status)
|
||||
{
|
||||
if(this->_status & status_have_value)
|
||||
{
|
||||
this->_status &= ~status_have_value;
|
||||
new(&_value) value_type; // NOLINT
|
||||
_status = o._status;
|
||||
}
|
||||
}
|
||||
explicit value_storage_nontrivial(status_bitfield_type status)
|
||||
: _empty()
|
||||
, _status(status)
|
||||
{
|
||||
}
|
||||
template <class... Args>
|
||||
explicit value_storage_nontrivial(in_place_type_t<value_type> /*unused*/, Args &&... args) noexcept(std::is_nothrow_constructible<value_type, Args...>::value)
|
||||
: _value(static_cast<Args &&>(args)...) // NOLINT
|
||||
, _status(status_have_value)
|
||||
{
|
||||
}
|
||||
template <class U, class... Args>
|
||||
value_storage_nontrivial(in_place_type_t<value_type> /*unused*/, std::initializer_list<U> il, Args &&... args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>::value)
|
||||
: _value(il, static_cast<Args &&>(args)...)
|
||||
, _status(status_have_value)
|
||||
{
|
||||
}
|
||||
template <class U> static constexpr bool enable_converting_constructor = !std::is_same<std::decay_t<U>, value_type>::value && std::is_constructible<value_type, U>::value;
|
||||
BOOST_OUTCOME_TEMPLATE(class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(enable_converting_constructor<U>))
|
||||
constexpr explicit value_storage_nontrivial(const value_storage_nontrivial<U> &o) noexcept(std::is_nothrow_constructible<value_type, U>::value)
|
||||
: value_storage_nontrivial((o._status & status_have_value) != 0 ? value_storage_nontrivial(in_place_type<value_type>, o._value) : value_storage_nontrivial())
|
||||
{
|
||||
_status = o._status;
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(enable_converting_constructor<U>))
|
||||
constexpr explicit value_storage_nontrivial(const value_storage_trivial<U> &o) noexcept(std::is_nothrow_constructible<value_type, U>::value)
|
||||
: value_storage_nontrivial((o._status & status_have_value) != 0 ? value_storage_nontrivial(in_place_type<value_type>, o._value) : value_storage_nontrivial())
|
||||
{
|
||||
_status = o._status;
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(enable_converting_constructor<U>))
|
||||
constexpr explicit value_storage_nontrivial(value_storage_nontrivial<U> &&o) noexcept(std::is_nothrow_constructible<value_type, U>::value)
|
||||
: value_storage_nontrivial((o._status & status_have_value) != 0 ? value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) : value_storage_nontrivial())
|
||||
{
|
||||
_status = o._status;
|
||||
}
|
||||
BOOST_OUTCOME_TEMPLATE(class U)
|
||||
BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(enable_converting_constructor<U>))
|
||||
constexpr explicit value_storage_nontrivial(value_storage_trivial<U> &&o) noexcept(std::is_nothrow_constructible<value_type, U>::value)
|
||||
: value_storage_nontrivial((o._status & status_have_value) != 0 ? value_storage_nontrivial(in_place_type<value_type>, static_cast<U &&>(o._value)) : value_storage_nontrivial())
|
||||
{
|
||||
_status = o._status;
|
||||
}
|
||||
~value_storage_nontrivial() noexcept(std::is_nothrow_destructible<T>::value)
|
||||
{
|
||||
if(this->_status & status_have_value)
|
||||
{
|
||||
this->_value.~value_type(); // NOLINT
|
||||
this->_status &= ~status_have_value;
|
||||
}
|
||||
}
|
||||
constexpr void swap(value_storage_nontrivial &o) noexcept(detail::is_nothrow_swappable<value_type>::value &&std::is_nothrow_move_constructible<value_type>::value)
|
||||
{
|
||||
using std::swap;
|
||||
if((_status & status_have_value) == 0 && (o._status & status_have_value) == 0)
|
||||
{
|
||||
swap(_status, o._status);
|
||||
return;
|
||||
}
|
||||
if((_status & status_have_value) != 0 && (o._status & status_have_value) != 0)
|
||||
{
|
||||
swap(_value, o._value); // NOLINT
|
||||
swap(_status, o._status);
|
||||
return;
|
||||
}
|
||||
// One must be empty and the other non-empty, so use move construction
|
||||
if((_status & status_have_value) != 0)
|
||||
{
|
||||
// Move construct me into other
|
||||
new(&o._value) value_type(static_cast<value_type &&>(_value)); // NOLINT
|
||||
this->_value.~value_type(); // NOLINT
|
||||
swap(_status, o._status);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move construct other into me
|
||||
new(&_value) value_type(static_cast<value_type &&>(o._value)); // NOLINT
|
||||
o._value.~value_type(); // NOLINT
|
||||
swap(_status, o._status);
|
||||
}
|
||||
}
|
||||
};
|
||||
template <class Base> struct value_storage_delete_copy_constructor : Base // NOLINT
|
||||
{
|
||||
using Base::Base;
|
||||
using value_type = typename Base::value_type;
|
||||
value_storage_delete_copy_constructor() = default;
|
||||
value_storage_delete_copy_constructor(const value_storage_delete_copy_constructor &) = delete;
|
||||
value_storage_delete_copy_constructor(value_storage_delete_copy_constructor &&) = default; // NOLINT
|
||||
};
|
||||
template <class Base> struct value_storage_delete_copy_assignment : Base // NOLINT
|
||||
{
|
||||
using Base::Base;
|
||||
using value_type = typename Base::value_type;
|
||||
value_storage_delete_copy_assignment() = default;
|
||||
value_storage_delete_copy_assignment(const value_storage_delete_copy_assignment &) = default;
|
||||
value_storage_delete_copy_assignment(value_storage_delete_copy_assignment &&) = default; // NOLINT
|
||||
value_storage_delete_copy_assignment &operator=(const value_storage_delete_copy_assignment &o) = delete;
|
||||
value_storage_delete_copy_assignment &operator=(value_storage_delete_copy_assignment &&o) = default; // NOLINT
|
||||
};
|
||||
template <class Base> struct value_storage_delete_move_assignment : Base // NOLINT
|
||||
{
|
||||
using Base::Base;
|
||||
using value_type = typename Base::value_type;
|
||||
value_storage_delete_move_assignment() = default;
|
||||
value_storage_delete_move_assignment(const value_storage_delete_move_assignment &) = default;
|
||||
value_storage_delete_move_assignment(value_storage_delete_move_assignment &&) = default; // NOLINT
|
||||
value_storage_delete_move_assignment &operator=(const value_storage_delete_move_assignment &o) = default;
|
||||
value_storage_delete_move_assignment &operator=(value_storage_delete_move_assignment &&o) = delete;
|
||||
};
|
||||
template <class Base> struct value_storage_delete_move_constructor : Base // NOLINT
|
||||
{
|
||||
using Base::Base;
|
||||
using value_type = typename Base::value_type;
|
||||
value_storage_delete_move_constructor() = default;
|
||||
value_storage_delete_move_constructor(const value_storage_delete_move_constructor &) = default;
|
||||
value_storage_delete_move_constructor(value_storage_delete_move_constructor &&) = delete;
|
||||
};
|
||||
template <class Base> struct value_storage_nontrivial_move_assignment : Base // NOLINT
|
||||
{
|
||||
using Base::Base;
|
||||
using value_type = typename Base::value_type;
|
||||
value_storage_nontrivial_move_assignment() = default;
|
||||
value_storage_nontrivial_move_assignment(const value_storage_nontrivial_move_assignment &) = default;
|
||||
value_storage_nontrivial_move_assignment(value_storage_nontrivial_move_assignment &&) = default; // NOLINT
|
||||
value_storage_nontrivial_move_assignment &operator=(const value_storage_nontrivial_move_assignment &o) = default;
|
||||
value_storage_nontrivial_move_assignment &operator=(value_storage_nontrivial_move_assignment &&o) noexcept(std::is_nothrow_move_assignable<value_type>::value) // NOLINT
|
||||
{
|
||||
if((this->_status & status_have_value) != 0 && (o._status & status_have_value) != 0)
|
||||
{
|
||||
this->_value = static_cast<value_type &&>(o._value); // NOLINT
|
||||
}
|
||||
else if((this->_status & status_have_value) != 0 && (o._status & status_have_value) == 0)
|
||||
{
|
||||
this->_value.~value_type(); // NOLINT
|
||||
}
|
||||
else if((this->_status & status_have_value) == 0 && (o._status & status_have_value) != 0)
|
||||
{
|
||||
new(&this->_value) value_type(static_cast<value_type &&>(o._value)); // NOLINT
|
||||
}
|
||||
this->_status = o._status;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
template <class Base> struct value_storage_nontrivial_copy_assignment : Base // NOLINT
|
||||
{
|
||||
using Base::Base;
|
||||
using value_type = typename Base::value_type;
|
||||
value_storage_nontrivial_copy_assignment() = default;
|
||||
value_storage_nontrivial_copy_assignment(const value_storage_nontrivial_copy_assignment &) = default;
|
||||
value_storage_nontrivial_copy_assignment(value_storage_nontrivial_copy_assignment &&) = default; // NOLINT
|
||||
value_storage_nontrivial_copy_assignment &operator=(value_storage_nontrivial_copy_assignment &&o) = default; // NOLINT
|
||||
value_storage_nontrivial_copy_assignment &operator=(const value_storage_nontrivial_copy_assignment &o) noexcept(std::is_nothrow_copy_assignable<value_type>::value)
|
||||
{
|
||||
if((this->_status & status_have_value) != 0 && (o._status & status_have_value) != 0)
|
||||
{
|
||||
this->_value = o._value; // NOLINT
|
||||
}
|
||||
else if((this->_status & status_have_value) != 0 && (o._status & status_have_value) == 0)
|
||||
{
|
||||
this->_value.~value_type(); // NOLINT
|
||||
}
|
||||
else if((this->_status & status_have_value) == 0 && (o._status & status_have_value) != 0)
|
||||
{
|
||||
new(&this->_value) value_type(o._value); // NOLINT
|
||||
}
|
||||
this->_status = o._status;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
// We don't actually need all of std::is_trivial<>, std::is_trivially_copyable<> is sufficient
|
||||
template <class T> using value_storage_select_trivality = std::conditional_t<std::is_trivially_copyable<devoid<T>>::value, value_storage_trivial<T>, value_storage_nontrivial<T>>;
|
||||
template <class T> using value_storage_select_move_constructor = std::conditional_t<std::is_move_constructible<devoid<T>>::value, value_storage_select_trivality<T>, value_storage_delete_move_constructor<value_storage_select_trivality<T>>>;
|
||||
template <class T> using value_storage_select_copy_constructor = std::conditional_t<std::is_copy_constructible<devoid<T>>::value, value_storage_select_move_constructor<T>, value_storage_delete_copy_constructor<value_storage_select_move_constructor<T>>>;
|
||||
template <class T>
|
||||
using value_storage_select_move_assignment = std::conditional_t<std::is_trivially_move_assignable<devoid<T>>::value, value_storage_select_copy_constructor<T>,
|
||||
std::conditional_t<std::is_move_assignable<devoid<T>>::value, value_storage_nontrivial_move_assignment<value_storage_select_copy_constructor<T>>, value_storage_delete_copy_assignment<value_storage_select_copy_constructor<T>>>>;
|
||||
template <class T>
|
||||
using value_storage_select_copy_assignment = std::conditional_t<std::is_trivially_copy_assignable<devoid<T>>::value, value_storage_select_move_assignment<T>,
|
||||
std::conditional_t<std::is_copy_assignable<devoid<T>>::value, value_storage_nontrivial_copy_assignment<value_storage_select_move_assignment<T>>, value_storage_delete_copy_assignment<value_storage_select_move_assignment<T>>>>;
|
||||
template <class T> using value_storage_select_impl = value_storage_select_copy_assignment<T>;
|
||||
#ifndef NDEBUG
|
||||
// Check is trivial in all ways except default constructibility
|
||||
// static_assert(std::is_trivial<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivial!");
|
||||
// static_assert(std::is_trivially_default_constructible<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially default constructible!");
|
||||
static_assert(std::is_trivially_copyable<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially copyable!");
|
||||
static_assert(std::is_trivially_assignable<value_storage_select_impl<int>, value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially assignable!");
|
||||
static_assert(std::is_trivially_destructible<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially destructible!");
|
||||
static_assert(std::is_trivially_copy_constructible<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially copy constructible!");
|
||||
static_assert(std::is_trivially_move_constructible<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially move constructible!");
|
||||
static_assert(std::is_trivially_copy_assignable<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially copy assignable!");
|
||||
static_assert(std::is_trivially_move_assignable<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not trivially move assignable!");
|
||||
// Also check is standard layout
|
||||
static_assert(std::is_standard_layout<value_storage_select_impl<int>>::value, "value_storage_select_impl<int> is not a standard layout type!");
|
||||
#endif
|
||||
} // namespace detail
|
||||
|
||||
BOOST_OUTCOME_V2_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user