Skip to content

Commit

Permalink
[libc++] Rework compressed pair constructors.
Browse files Browse the repository at this point in the history
This patch de-duplicates most compressed pair constructors
to use the same code in C++11 and C++03.

Part of doing that is deleting the "__second_tag()" and replacing
it with a "__value_init_tag()" which has the same effect, but
allows for the removal of the special "one-arg" first element
constructor.

This patch is intended to have no semantic change.
  • Loading branch information
EricWF committed Dec 16, 2019
1 parent f63b64c commit 549545b
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 113 deletions.
8 changes: 4 additions & 4 deletions libcxx/include/__functional_03
Expand Up @@ -104,7 +104,7 @@ class __func<_Fp, _Alloc, _Rp()>
{
__compressed_pair<_Fp, _Alloc> __f_;
public:
explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {}
explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
virtual __base<_Rp()>* __clone() const;
virtual void __clone(__base<_Rp()>*) const;
Expand Down Expand Up @@ -189,7 +189,7 @@ class __func<_Fp, _Alloc, _Rp(_A0)>
{
__compressed_pair<_Fp, _Alloc> __f_;
public:
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {}
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
: __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
virtual __base<_Rp(_A0)>* __clone() const;
Expand Down Expand Up @@ -275,7 +275,7 @@ class __func<_Fp, _Alloc, _Rp(_A0, _A1)>
{
__compressed_pair<_Fp, _Alloc> __f_;
public:
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {}
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
: __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
virtual __base<_Rp(_A0, _A1)>* __clone() const;
Expand Down Expand Up @@ -361,7 +361,7 @@ class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>
{
__compressed_pair<_Fp, _Alloc> __f_;
public:
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f), __default_init_tag()) {}
_LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
: __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const;
Expand Down
20 changes: 10 additions & 10 deletions libcxx/include/__hash_table
Expand Up @@ -776,7 +776,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
__bucket_list_deallocator()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __data_(0) {}
: __data_(0, __default_init_tag()) {}

_LIBCPP_INLINE_VISIBILITY
__bucket_list_deallocator(const allocator_type& __a, size_type __size)
Expand Down Expand Up @@ -1418,8 +1418,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
is_nothrow_default_constructible<__node_allocator>::value &&
is_nothrow_default_constructible<hasher>::value &&
is_nothrow_default_constructible<key_equal>::value)
: __p2_(0),
__p3_(1.0f)
: __p2_(0, __default_init_tag()),
__p3_(1.0f, __default_init_tag())
{
}

Expand All @@ -1439,7 +1439,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
const key_equal& __eql,
const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p1_(__default_init_tag(), __node_allocator(__a)),
__p2_(0, __hf),
__p3_(1.0f, __eql)
{
Expand All @@ -1448,9 +1448,9 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p2_(0),
__p3_(1.0f)
__p1_(__default_init_tag(), __node_allocator(__a)),
__p2_(0, __default_init_tag()),
__p3_(1.0f, __default_init_tag())
{
}

Expand All @@ -1460,7 +1460,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
__bucket_list_deleter(allocator_traits<__pointer_allocator>::
select_on_container_copy_construction(
__u.__bucket_list_.get_deleter().__alloc()), 0)),
__p1_(__second_tag(), allocator_traits<__node_allocator>::
__p1_(__default_init_tag(), allocator_traits<__node_allocator>::
select_on_container_copy_construction(__u.__node_alloc())),
__p2_(0, __u.hash_function()),
__p3_(__u.__p3_)
Expand All @@ -1471,7 +1471,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p1_(__default_init_tag(), __node_allocator(__a)),
__p2_(0, __u.hash_function()),
__p3_(__u.__p3_)
{
Expand Down Expand Up @@ -1505,7 +1505,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p1_(__default_init_tag(), __node_allocator(__a)),
__p2_(0, _VSTD::move(__u.hash_function())),
__p3_(_VSTD::move(__u.__p3_))
{
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__split_buffer
Expand Up @@ -324,7 +324,7 @@ template <class _Tp, class _Allocator>
inline
__split_buffer<_Tp, _Allocator>::__split_buffer()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr)
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __default_init_tag())
{
}

Expand Down Expand Up @@ -368,7 +368,7 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)

template <class _Tp, class _Allocator>
__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a)
: __end_cap_(__second_tag(), __a)
: __end_cap_(nullptr, __a)
{
if (__a == __c.__alloc())
{
Expand Down
10 changes: 5 additions & 5 deletions libcxx/include/__tree
Expand Up @@ -1577,8 +1577,8 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp)
template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
: __begin_node_(__iter_pointer()),
__pair1_(__second_tag(), __node_allocator(__a)),
__pair3_(0)
__pair1_(__default_init_tag(), __node_allocator(__a)),
__pair3_(0, __default_init_tag())
{
__begin_node() = __end_node();
}
Expand All @@ -1587,7 +1587,7 @@ template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp,
const allocator_type& __a)
: __begin_node_(__iter_pointer()),
__pair1_(__second_tag(), __node_allocator(__a)),
__pair1_(__default_init_tag(), __node_allocator(__a)),
__pair3_(0, __comp)
{
__begin_node() = __end_node();
Expand Down Expand Up @@ -1700,7 +1700,7 @@ __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _Input
template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
: __begin_node_(__iter_pointer()),
__pair1_(__second_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())),
__pair1_(__default_init_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())),
__pair3_(0, __t.value_comp())
{
__begin_node() = __end_node();
Expand Down Expand Up @@ -1730,7 +1730,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t)

template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a)
: __pair1_(__second_tag(), __node_allocator(__a)),
: __pair1_(__default_init_tag(), __node_allocator(__a)),
__pair3_(0, _VSTD::move(__t.value_comp()))
{
if (__a == __t.__alloc())
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/deque
Expand Up @@ -1171,7 +1171,7 @@ template <class _Tp, class _Allocator>
inline
__deque_base<_Tp, _Allocator>::__deque_base()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __start_(0), __size_(0) {}
: __start_(0), __size_(0, __default_init_tag()) {}

template <class _Tp, class _Allocator>
inline
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/forward_list
Expand Up @@ -490,7 +490,7 @@ protected:
_LIBCPP_INLINE_VISIBILITY
__forward_list_base()
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
: __before_begin_(__begin_node()) {}
: __before_begin_(__begin_node(), __default_init_tag()) {}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_base(const allocator_type& __a)
: __before_begin_(__begin_node(), __node_allocator(__a)) {}
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/future
Expand Up @@ -1767,9 +1767,9 @@ class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_func<_Fp, _Alloc, _Rp(_ArgType
__compressed_pair<_Fp, _Alloc> __f_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {}
explicit __packaged_task_func(const _Fp& __f) : __f_(__f, __default_init_tag()) {}
_LIBCPP_INLINE_VISIBILITY
explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f), __default_init_tag()) {}
_LIBCPP_INLINE_VISIBILITY
__packaged_task_func(const _Fp& __f, const _Alloc& __a)
: __f_(__f, __a) {}
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/list
Expand Up @@ -715,7 +715,7 @@ template <class _Tp, class _Alloc>
inline
__list_imp<_Tp, _Alloc>::__list_imp()
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
: __size_alloc_(0)
: __size_alloc_(0, __default_init_tag())
{
}

Expand Down

0 comments on commit 549545b

Please sign in to comment.