@@ -162,9 +162,19 @@ class flat_set
162162 public totally_ordered<flat_set<T, Compare, Allocator>> {
163163 using base_type = flat_detail::flat_base<T, Compare, Allocator>;
164164 using storage_type = typename base_type::storage_type;
165+ using storage_iterator = typename storage_type::iterator;
166+ using storage_const_iterator = typename storage_type::const_iterator;
165167 using base_type::data;
166168 using base_type::comp;
167169
170+ #if defined(SMALL_VECTOR_IS_STL_VECTOR)
171+ // Construct a non-const iterator from a const iterator. Used in flat_map
172+ // and flat_set erase() calls to work around g++-4.8 compatibility issues.
173+ storage_iterator mutable_iterator (storage_const_iterator it) {
174+ return data ().begin () + std::distance (data ().cbegin (), it);
175+ }
176+ #endif
177+
168178public:
169179 // Member types.
170180 using key_type = T;
@@ -282,11 +292,27 @@ class flat_set
282292 }
283293
284294 void erase (const_iterator pos) {
285- data ().erase (pos.get ());
295+ #if defined(SMALL_VECTOR_IS_STL_VECTOR)
296+ // Cope with libstdc++ 4.8's incomplete STL (it's missing C++11
297+ // vector::erase(const_iterator)) by explicitly using a non-const
298+ // iterator.
299+ auto pos_it = mutable_iterator (pos.get ());
300+ #else
301+ auto pos_it = pos.get ();
302+ #endif
303+ data ().erase (pos_it);
286304 }
287305
288306 void erase (const_iterator first, const_iterator last) {
289- data ().erase (first.get (), last.get ());
307+ #if defined(SMALL_VECTOR_IS_STL_VECTOR)
308+ // As above, work around libstdc++ 4.8's incomplete C++11 support.
309+ auto first_it = mutable_iterator (first.get ());
310+ auto last_it = mutable_iterator (last.get ());
311+ #else
312+ auto first_it = first.get ();
313+ auto last_it = last.get ();
314+ #endif
315+ data ().erase (first_it, last_it);
290316 }
291317
292318 void erase (const key_type &key) {
@@ -374,9 +400,19 @@ class flat_map
374400 flat_detail::flat_base<std::pair<Key, T>, Compare, Allocator>;
375401 using keyval_storage_type = std::pair<key_type, mapped_type>;
376402 using storage_type = typename base_type::storage_type;
403+ using storage_iterator = typename storage_type::iterator;
404+ using storage_const_iterator = typename storage_type::const_iterator;
377405 using base_type::data;
378406 using base_type::comp;
379407
408+ #if defined(SMALL_VECTOR_IS_STL_VECTOR)
409+ // Construct a non-const iterator from a const iterator. Used in flat_map
410+ // and flat_set erase() calls to work around g++-4.8 compatibility issues.
411+ storage_iterator mutable_iterator (storage_const_iterator it) {
412+ return data ().begin () + std::distance (data ().cbegin (), it);
413+ }
414+ #endif
415+
380416public:
381417 // More Member types.
382418 using size_type = typename storage_type::size_type;
@@ -444,9 +480,6 @@ class flat_map
444480 const_reverse_iterator rend () const { return crend (); }
445481
446482private:
447- using storage_iterator = typename storage_type::iterator;
448- using storage_const_iterator = typename storage_type::const_iterator;
449-
450483 storage_iterator data_lower_bound (const key_type &key) {
451484 return std::lower_bound (
452485 data ().begin (), data ().end (), key,
@@ -526,11 +559,27 @@ class flat_map
526559 }
527560
528561 void erase (const_iterator pos) {
529- data ().erase (pos.get ());
562+ #if defined(SMALL_VECTOR_IS_STL_VECTOR)
563+ // Cope with libstdc++ 4.8's incomplete STL (it's missing C++11
564+ // vector::erase(const_iterator)) by explicitly using a non-const
565+ // iterator.
566+ auto pos_it = mutable_iterator (pos.get ());
567+ #else
568+ auto pos_it = pos.get ();
569+ #endif
570+ data ().erase (pos_it);
530571 }
531572
532573 void erase (const_iterator first, const_iterator last) {
533- data ().erase (first.get (), last.get ());
574+ #if defined(SMALL_VECTOR_IS_STL_VECTOR)
575+ // As above, work around libstdc++ 4.8's incomplete C++11 support.
576+ auto first_it = mutable_iterator (first.get ());
577+ auto last_it = mutable_iterator (last.get ());
578+ #else
579+ auto first_it = first.get ();
580+ auto last_it = last.get ();
581+ #endif
582+ data ().erase (first_it, last_it);
534583 }
535584
536585 void erase (const key_type &key) {
0 commit comments