Skip to content

Commit

Permalink
[flat_foo] Fix uses of std::initializer_list
Browse files Browse the repository at this point in the history
And use uses-allocator construction in flat_set's copy/move constructors.
  • Loading branch information
Quuxplusone committed Nov 6, 2023
1 parent 94c0c7c commit 27aa360
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
24 changes: 12 additions & 12 deletions include/sg14/flat_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,31 +525,31 @@ class flat_map {
values_(flatmap_detail::make_obj_using_allocator<MappedContainer>(a, m.values_)),
compare_(m.compare_) {}

flat_map(std::initializer_list<value_type>&& il, const Compare& comp = Compare())
: flat_map(il, comp) {}
flat_map(std::initializer_list<value_type> il, const Compare& comp = Compare())
: flat_map(il.begin(), il.end(), comp) {}

template<class Alloc,
typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value && std::uses_allocator<MappedContainer, Alloc>::value, int>::type = 0>
flat_map(std::initializer_list<value_type>&& il, const Compare& comp, const Alloc& a)
: flat_map(il, comp, a) {}
flat_map(std::initializer_list<value_type> il, const Compare& comp, const Alloc& a)
: flat_map(il.begin(), il.end(), comp, a) {}

template<class Alloc,
typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value && std::uses_allocator<MappedContainer, Alloc>::value, int>::type = 0>
flat_map(std::initializer_list<value_type>&& il, const Alloc& a)
: flat_map(il, Compare(), a) {}
flat_map(std::initializer_list<value_type> il, const Alloc& a)
: flat_map(il.begin(), il.end(), a) {}

flat_map(sorted_unique_t s, std::initializer_list<value_type>&& il, const Compare& comp = Compare())
: flat_map(s, il, comp) {}
flat_map(sorted_unique_t s, std::initializer_list<value_type> il, const Compare& comp = Compare())
: flat_map(s, il.begin(), il.end(), comp) {}

template<class Alloc,
typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value && std::uses_allocator<MappedContainer, Alloc>::value, int>::type = 0>
flat_map(sorted_unique_t s, std::initializer_list<value_type>&& il, const Compare& comp, const Alloc& a)
: flat_map(s, il, comp, a) {}
flat_map(sorted_unique_t s, std::initializer_list<value_type> il, const Compare& comp, const Alloc& a)
: flat_map(s, il.begin(), il.end(), comp, a) {}

template<class Alloc,
typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value && std::uses_allocator<MappedContainer, Alloc>::value, int>::type = 0>
flat_map(sorted_unique_t s, std::initializer_list<value_type>&& il, const Alloc& a)
: flat_map(s, il, Compare(), a) {}
flat_map(sorted_unique_t s, std::initializer_list<value_type> il, const Alloc& a)
: flat_map(s, il.begin(), il.end(), Compare(), a) {}

// ========================================================== OTHER MEMBERS

Expand Down
38 changes: 24 additions & 14 deletions include/sg14/flat_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,38 +314,48 @@ class flat_set {
template<class Alloc,
class = typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value>::type>
flat_set(flat_set&& m, const Alloc& a)
: c_(static_cast<KeyContainer&&>(m.c_), a), compare_(static_cast<Compare&&>(m.compare_)) {}
: c_(flatset_detail::make_obj_using_allocator<KeyContainer>(a, static_cast<KeyContainer&&>(m.c_))),
compare_(static_cast<Compare&&>(m.compare_)) {}

template<class Alloc,
class = typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value>::type>
flat_set(const flat_set& m, const Alloc& a)
: c_(m.c_, a), compare_(m.compare_) {}
: c_(flatset_detail::make_obj_using_allocator<KeyContainer>(a, m.c_)), compare_(m.compare_) {}

flat_set(std::initializer_list<Key>&& il, const Compare& comp = Compare())
: flat_set(il, comp) {}
flat_set(std::initializer_list<Key> il, const Compare& comp = Compare())
: c_(il), compare_(comp)
{
this->sort_and_unique_impl();
}

template<class Alloc,
class = typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value>::type>
flat_set(std::initializer_list<Key>&& il, const Compare& comp, const Alloc& a)
: flat_set(il, comp, a) {}
flat_set(std::initializer_list<Key> il, const Compare& comp, const Alloc& a)
: c_(flatset_detail::make_obj_using_allocator<KeyContainer>(a, il)), compare_(comp)
{
this->sort_and_unique_impl();
}

template<class Alloc,
class = typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value>::type>
flat_set(std::initializer_list<Key>&& il, const Alloc& a)
: flat_set(il, Compare(), a) {}
flat_set(std::initializer_list<Key> il, const Alloc& a)
: c_(flatset_detail::make_obj_using_allocator<KeyContainer>(a, il))
{
this->sort_and_unique_impl();
}

flat_set(sorted_unique_t s, std::initializer_list<Key>&& il, const Compare& comp = Compare())
: flat_set(s, il, comp) {}
flat_set(sorted_unique_t, std::initializer_list<Key> il, const Compare& comp = Compare())
: c_(il), compare_(comp) {}

template<class Alloc,
class = typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value>::type>
flat_set(sorted_unique_t s, std::initializer_list<Key>&& il, const Compare& comp, const Alloc& a)
: flat_set(s, il, comp, a) {}
flat_set(sorted_unique_t, std::initializer_list<Key> il, const Compare& comp, const Alloc& a)
: c_(flatset_detail::make_obj_using_allocator<KeyContainer>(a, il)), compare_(comp) {}

template<class Alloc,
class = typename std::enable_if<std::uses_allocator<KeyContainer, Alloc>::value>::type>
flat_set(sorted_unique_t s, std::initializer_list<Key>&& il, const Alloc& a)
: flat_set(s, il, Compare(), a) {}
flat_set(sorted_unique_t, std::initializer_list<Key> il, const Alloc& a)
: c_(flatset_detail::make_obj_using_allocator<KeyContainer>(a, il)) {}


// ========================================================== OTHER MEMBERS
Expand Down

0 comments on commit 27aa360

Please sign in to comment.