From 3094aeedfab6411ea24a585d8ab3d35d8bbd4cfc Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Fri, 8 Sep 2017 04:18:39 -0700 Subject: [PATCH] fix build error using libstdc++ 7.2 Closes #2 --- src/util/enum.h | 70 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/src/util/enum.h b/src/util/enum.h index f40bec2..e7b10f4 100644 --- a/src/util/enum.h +++ b/src/util/enum.h @@ -478,6 +478,7 @@ public: namespace detail { template ::value, bool Is_Trivially_Copyable = std::is_trivially_copyable::value> @@ -544,14 +545,15 @@ struct Enum_map_base } Enum_map_base &operator=(const Enum_map_base &rt) noexcept( noexcept(new(std::declval()) T(std::declval())) - && noexcept(std::declval() = std::declval())) + && noexcept(std::declval() = std::declval())) { auto either_full = full_entries | rt.full_entries; for(std::size_t index = either_full.find_first(true); index != Bits::npos; index = either_full.find_first(true, index + 1)) if(rt.full_entries[index]) if(full_entries[index]) - entries[index].full_value = rt.entries[index].full_value; + std::get<1>(entries[index].full_value) = + std::get<1>(rt.entries[index].full_value); else emplace_at_index(index, rt.entries[index].full_value); else @@ -560,14 +562,15 @@ struct Enum_map_base } Enum_map_base &operator=(Enum_map_base &&rt) noexcept( noexcept(new(std::declval()) T(std::declval())) - && noexcept(std::declval() = std::declval())) + && noexcept(std::declval() = std::declval())) { auto either_full = full_entries | rt.full_entries; for(std::size_t index = either_full.find_first(true); index != Bits::npos; index = either_full.find_first(true, index + 1)) if(rt.full_entries[index]) if(full_entries[index]) - entries[index].full_value = std::move(rt.entries[index].full_value); + std::get<1>(entries[index].full_value) = + std::move(std::get<1>(rt.entries[index].full_value)); else emplace_at_index(index, std::move(rt.entries[index].full_value)); else @@ -586,8 +589,8 @@ struct Enum_map_base } }; -template -struct Enum_map_base +template +struct Enum_map_base { union Entry_type { @@ -646,14 +649,15 @@ struct Enum_map_base } Enum_map_base &operator=(const Enum_map_base &rt) noexcept( noexcept(new(std::declval()) T(std::declval())) - && noexcept(std::declval() = std::declval())) + && noexcept(std::declval() = std::declval())) { auto either_full = full_entries | rt.full_entries; for(std::size_t index = either_full.find_first(true); index != Bits::npos; index = either_full.find_first(true, index + 1)) if(rt.full_entries[index]) if(full_entries[index]) - entries[index].full_value = rt.entries[index].full_value; + std::get<1>(entries[index].full_value) = + std::get<1>(rt.entries[index].full_value); else emplace_at_index(index, rt.entries[index].full_value); else @@ -662,14 +666,15 @@ struct Enum_map_base } Enum_map_base &operator=(Enum_map_base &&rt) noexcept( noexcept(new(std::declval()) T(std::declval())) - && noexcept(std::declval() = std::declval())) + && noexcept(std::declval() = std::declval())) { auto either_full = full_entries | rt.full_entries; for(std::size_t index = either_full.find_first(true); index != Bits::npos; index = either_full.find_first(true, index + 1)) if(rt.full_entries[index]) if(full_entries[index]) - entries[index].full_value = std::move(rt.entries[index].full_value); + std::get<1>(entries[index].full_value) = + std::move(std::get<1>(rt.entries[index].full_value)); else emplace_at_index(index, std::move(rt.entries[index].full_value)); else @@ -685,8 +690,8 @@ struct Enum_map_base ~Enum_map_base() = default; }; -template -struct Enum_map_base +template +struct Enum_map_base { union Entry_type { @@ -717,8 +722,40 @@ struct Enum_map_base } constexpr Enum_map_base(const Enum_map_base &rt) noexcept = default; constexpr Enum_map_base(Enum_map_base &&rt) noexcept = default; - constexpr Enum_map_base &operator=(const Enum_map_base &rt) noexcept = default; - constexpr Enum_map_base &operator=(Enum_map_base &&rt) noexcept = default; + Enum_map_base &operator=(const Enum_map_base &rt) noexcept( + noexcept(new(std::declval()) T(std::declval())) + && noexcept(std::declval() = std::declval())) + { + auto either_full = full_entries | rt.full_entries; + for(std::size_t index = either_full.find_first(true); index != Bits::npos; + index = either_full.find_first(true, index + 1)) + if(rt.full_entries[index]) + if(full_entries[index]) + std::get<1>(entries[index].full_value) = + std::get<1>(rt.entries[index].full_value); + else + emplace_at_index(index, rt.entries[index].full_value); + else + erase_at_index(index); + return *this; + } + Enum_map_base &operator=(Enum_map_base &&rt) noexcept( + noexcept(new(std::declval()) T(std::declval())) + && noexcept(std::declval() = std::declval())) + { + auto either_full = full_entries | rt.full_entries; + for(std::size_t index = either_full.find_first(true); index != Bits::npos; + index = either_full.find_first(true, index + 1)) + if(rt.full_entries[index]) + if(full_entries[index]) + std::get<1>(entries[index].full_value) = + std::move(std::get<1>(rt.entries[index].full_value)); + else + emplace_at_index(index, std::move(rt.entries[index].full_value)); + else + erase_at_index(index); + return *this; + } constexpr void clear() noexcept { for(std::size_t index = full_entries.find_first(true); index != Bits::npos; @@ -731,10 +768,11 @@ struct Enum_map_base /** behaves like a std::map */ template -class Enum_map : private detail::Enum_map_base, Enum_traits::value_count> +class Enum_map + : private detail::Enum_map_base, V, Enum_traits::value_count> { private: - typedef detail::Enum_map_base, Enum_traits::value_count> Base; + typedef detail::Enum_map_base, V, Enum_traits::value_count> Base; public: typedef K key_type; -- 2.30.2