Skip to content

Commit

Permalink
Delete unnecessary member types in bitset and add SFINAE
Browse files Browse the repository at this point in the history
  • Loading branch information
winner245 committed Jan 9, 2025
1 parent c5d4654 commit 4fa6a82
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
13 changes: 10 additions & 3 deletions libcxx/include/__bit_reference
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <__memory/pointer_traits.h>
#include <__type_traits/conditional.h>
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/void_t.h>
#include <__utility/swap.h>

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

template <typename _Cp>
template <class, class>
struct __size_difference_type_traits {
using difference_type = ptrdiff_t;
using size_type = size_t;
};

template <class _Cp>
struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type, typename _Cp::size_type> > {
using difference_type = typename _Cp::difference_type;
using size_type = typename _Cp::size_type;
};
Expand Down Expand Up @@ -595,9 +602,9 @@ inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> swap_ranges(
template <class _Cp>
struct __bit_array {
using difference_type _LIBCPP_NODEBUG = typename __size_difference_type_traits<_Cp>::difference_type;
using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer;
using iterator _LIBCPP_NODEBUG = typename _Cp::iterator;
using iterator _LIBCPP_NODEBUG = typename _Cp::iterator;

static const unsigned __bits_per_word = _Cp::__bits_per_word;
static const unsigned _Np = 4;
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__fwd/bit_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
class __bit_iterator;

template <typename _Cp>
template <class, class = void>
struct __size_difference_type_traits;

_LIBCPP_END_NAMESPACE_STD
Expand Down
12 changes: 0 additions & 12 deletions libcxx/include/bitset
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,9 @@ struct __has_storage_type<__bitset<_N_words, _Size> > {
static const bool value = true;
};

template <size_t _N_words, size_t _Size>
struct __size_difference_type_traits<std::__bitset<_N_words, _Size> > {
using difference_type = typename std::__bitset<_N_words, _Size>::__difference_type;
using size_type = typename std::__bitset<_N_words, _Size>::__size_type;
};

template <size_t _N_words, size_t _Size>
class __bitset {
public:
typedef ptrdiff_t __difference_type;
typedef size_t __size_type;
typedef size_t __storage_type;

protected:
Expand Down Expand Up @@ -440,8 +432,6 @@ inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
template <size_t _Size>
class __bitset<1, _Size> {
public:
typedef ptrdiff_t __difference_type;
typedef size_t __size_type;
typedef size_t __storage_type;

protected:
Expand Down Expand Up @@ -557,8 +547,6 @@ inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
template <>
class __bitset<0, 0> {
public:
typedef ptrdiff_t __difference_type;
typedef size_t __size_type;
typedef size_t __storage_type;

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ struct my_base {
typedef int* iterator;
typedef const int* const_iterator;
typedef my_base base;
<<<<<<< HEAD
typedef const int& const_reference;
=======
typedef std::ptrdiff_t difference_type;
typedef std::size_t size_type;
>>>>>>> 620da4a790b5 (Fix ambiguity due to non-uglified member typedefs)
};

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

0 comments on commit 4fa6a82

Please sign in to comment.