Skip to content
Browse files

Properly mark noexcept status of swap member and free function

  • Loading branch information...
1 parent 84e2dda commit ba271a5cc24f612d6cca0188ec60a865edfdb3b9 @acmorrow committed
Showing with 12 additions and 10 deletions.
  1. +12 −10 error_or.hpp
View
22 error_or.hpp
@@ -32,6 +32,16 @@ namespace acm {
using error_type = E;
using value_type = T;
+ private:
+ static bool constexpr is_nothrow_swappable =
+ detail::is_nothrow_swappable<error_type>::value and
+ detail::is_nothrow_swappable<value_type>::value and
+ std::is_nothrow_move_constructible<error_type>::value and
+ std::is_nothrow_move_constructible<value_type>::value and
+ std::is_nothrow_destructible<error_type>::value and
+ std::is_nothrow_destructible<value_type>::value;
+
+ public:
inline error_or() noexcept(std::is_nothrow_default_constructible<value_type>::value) {
new(&val_.value) value_type;
}
@@ -93,11 +103,11 @@ namespace acm {
ok_ = other.ok_;
}
- void swap(error_or& other) noexcept {
+ void swap(error_or& other) noexcept(is_nothrow_swappable) {
other.sfinae_swap(*this);
}
- friend inline void swap(error_or& a, error_or& b) noexcept {
+ friend inline void swap(error_or& a, error_or& b) noexcept(is_nothrow_swappable) {
a.swap(b);
}
@@ -174,14 +184,6 @@ namespace acm {
bool ok_ = true;
- static bool constexpr is_nothrow_swappable =
- detail::is_nothrow_swappable<error_type>::value and
- detail::is_nothrow_swappable<value_type>::value and
- std::is_nothrow_move_constructible<error_type>::value and
- std::is_nothrow_move_constructible<value_type>::value and
- std::is_nothrow_destructible<error_type>::value and
- std::is_nothrow_destructible<value_type>::value;
-
template<typename U = value_type>
typename std::enable_if<error_or<error_type, U>::is_nothrow_swappable>::type sfinae_swap(error_or& other) noexcept {
using std::swap;

0 comments on commit ba271a5

Please sign in to comment.
Something went wrong with that request. Please try again.