Skip to content

Commit fe5476f

Browse files
committed
Delete unnecessary member types in bitset and add SFINAE
1 parent b0ea215 commit fe5476f

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

libcxx/include/__bit_reference

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <__memory/pointer_traits.h>
2424
#include <__type_traits/conditional.h>
2525
#include <__type_traits/is_constant_evaluated.h>
26+
#include <__type_traits/void_t.h>
2627
#include <__utility/swap.h>
2728

2829
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -42,8 +43,14 @@ struct __has_storage_type {
4243
static const bool value = false;
4344
};
4445

45-
template <typename _Cp>
46+
template <class, class>
4647
struct __size_difference_type_traits {
48+
using difference_type = ptrdiff_t;
49+
using size_type = size_t;
50+
};
51+
52+
template <class _Cp>
53+
struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type, typename _Cp::size_type> > {
4754
using difference_type = typename _Cp::difference_type;
4855
using size_type = typename _Cp::size_type;
4956
};
@@ -595,9 +602,9 @@ inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> swap_ranges(
595602
template <class _Cp>
596603
struct __bit_array {
597604
using difference_type _LIBCPP_NODEBUG = typename __size_difference_type_traits<_Cp>::difference_type;
598-
using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
605+
using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
599606
using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer;
600-
using iterator _LIBCPP_NODEBUG = typename _Cp::iterator;
607+
using iterator _LIBCPP_NODEBUG = typename _Cp::iterator;
601608

602609
static const unsigned __bits_per_word = _Cp::__bits_per_word;
603610
static const unsigned _Np = 4;

libcxx/include/__fwd/bit_reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
2121
class __bit_iterator;
2222

23-
template <typename _Cp>
23+
template <class, class = void>
2424
struct __size_difference_type_traits;
2525

2626
_LIBCPP_END_NAMESPACE_STD

libcxx/include/bitset

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,9 @@ struct __has_storage_type<__bitset<_N_words, _Size> > {
169169
static const bool value = true;
170170
};
171171

172-
template <size_t _N_words, size_t _Size>
173-
struct __size_difference_type_traits<std::__bitset<_N_words, _Size> > {
174-
using difference_type = typename std::__bitset<_N_words, _Size>::__difference_type;
175-
using size_type = typename std::__bitset<_N_words, _Size>::__size_type;
176-
};
177-
178172
template <size_t _N_words, size_t _Size>
179173
class __bitset {
180174
public:
181-
typedef ptrdiff_t __difference_type;
182-
typedef size_t __size_type;
183175
typedef size_t __storage_type;
184176

185177
protected:
@@ -440,8 +432,6 @@ inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
440432
template <size_t _Size>
441433
class __bitset<1, _Size> {
442434
public:
443-
typedef ptrdiff_t __difference_type;
444-
typedef size_t __size_type;
445435
typedef size_t __storage_type;
446436

447437
protected:
@@ -557,8 +547,6 @@ inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
557547
template <>
558548
class __bitset<0, 0> {
559549
public:
560-
typedef ptrdiff_t __difference_type;
561-
typedef size_t __size_type;
562550
typedef size_t __storage_type;
563551

564552
protected:

libcxx/test/std/utilities/template.bitset/bitset.members/nonstdmem.uglified.compile.pass.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ struct my_base {
2424
typedef int* iterator;
2525
typedef const int* const_iterator;
2626
typedef my_base base;
27-
<<<<<<< HEAD
2827
typedef const int& const_reference;
29-
=======
3028
typedef std::ptrdiff_t difference_type;
3129
typedef std::size_t size_type;
32-
>>>>>>> 620da4a790b5 (Fix ambiguity due to non-uglified member typedefs)
3330
};
3431

3532
template <std::size_t N>
@@ -94,4 +91,3 @@ static_assert(std::is_same<my_derived<32>::size_type, std::size_t>::value, "");
9491
static_assert(std::is_same<my_derived<48>::size_type, std::size_t>::value, "");
9592
static_assert(std::is_same<my_derived<64>::size_type, std::size_t>::value, "");
9693
static_assert(std::is_same<my_derived<96>::size_type, std::size_t>::value, "");
97-
>>>>>>> 620da4a790b5 (Fix ambiguity due to non-uglified member typedefs)

0 commit comments

Comments
 (0)