From a38ac6a52f153d1015a0fa589d74a22c1ec25687 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Fri, 20 Jan 2017 16:12:59 +1100 Subject: [PATCH] flat_base: take more common operations --- src/util/ue2_containers.h | 45 +++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/util/ue2_containers.h b/src/util/ue2_containers.h index 47477ed7..3e0d1555 100644 --- a/src/util/ue2_containers.h +++ b/src/util/ue2_containers.h @@ -113,6 +113,18 @@ protected: Compare &comp() { return std::get<1>(this->storage); } const Compare &comp() const { return std::get<1>(this->storage); } + +public: + // Common member types. + using key_compare = Compare; + + Allocator get_allocator() const { + return data().get_allocator(); + } + + key_compare key_comp() const { + return comp(); + } }; } // namespace flat_detail @@ -127,8 +139,9 @@ protected: */ template , class Allocator = std::allocator> -class flat_set : flat_detail::flat_base, - boost::totally_ordered> { +class flat_set + : public flat_detail::flat_base, + public boost::totally_ordered> { using base_type = flat_detail::flat_base; using storage_type = typename base_type::storage_type; using base_type::data; @@ -140,7 +153,7 @@ public: using value_type = T; using size_type = typename storage_type::size_type; using difference_type = typename storage_type::difference_type; - using key_compare = Compare; + using key_compare = typename base_type::key_compare; using value_compare = Compare; using allocator_type = Allocator; using reference = value_type &; @@ -185,11 +198,6 @@ public: flat_set &operator=(const flat_set &) = default; flat_set &operator=(flat_set &&) = default; - // Other members. - - allocator_type get_allocator() const { - return data().get_allocator(); - } // Iterators. @@ -311,10 +319,6 @@ public: // Observers. - key_compare key_comp() const { - return comp(); - } - value_compare value_comp() const { return comp(); } @@ -355,8 +359,9 @@ public: */ template , class Allocator = std::allocator>> -class flat_map : flat_detail::flat_base, Compare, Allocator>, - boost::totally_ordered> { +class flat_map + : public flat_detail::flat_base, Compare, Allocator>, + public boost::totally_ordered> { public: // Member types. using key_type = Key; @@ -375,7 +380,7 @@ public: // More Member types. using size_type = typename storage_type::size_type; using difference_type = typename storage_type::difference_type; - using key_compare = Compare; + using key_compare = typename base_type::key_compare; using allocator_type = Allocator; using reference = value_type &; using const_reference = const value_type &; @@ -419,12 +424,6 @@ public: flat_map &operator=(const flat_map &) = default; flat_map &operator=(flat_map &&) = default; - // Other members. - - allocator_type get_allocator() const { - return data().get_allocator(); - } - // Iterators. const_iterator cbegin() const { return const_iterator(data().cbegin()); } @@ -596,10 +595,6 @@ public: // Observers. - key_compare key_comp() const { - return comp(); - } - class value_compare { friend class flat_map; protected: