Apply constexpr to <bitset>.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@159899 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
74f26f251b
commit
90d8723476
@ -131,13 +131,14 @@ public:
|
|||||||
__bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
|
__bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
|
||||||
: __seg_(__x.__seg_), __mask_(__x.__mask_) {}
|
: __seg_(__x.__seg_), __mask_(__x.__mask_) {}
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT
|
||||||
{return static_cast<bool>(*__seg_ & __mask_);}
|
{return static_cast<bool>(*__seg_ & __mask_);}
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
|
||||||
{return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
|
{return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
|
||||||
private:
|
private:
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR
|
||||||
__bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
|
__bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
|
||||||
: __seg_(__s), __mask_(__m) {}
|
: __seg_(__s), __mask_(__m) {}
|
||||||
|
|
||||||
|
@ -168,12 +168,12 @@ protected:
|
|||||||
typedef __bit_iterator<__bitset, false> iterator;
|
typedef __bit_iterator<__bitset, false> iterator;
|
||||||
typedef __bit_iterator<__bitset, true> const_iterator;
|
typedef __bit_iterator<__bitset, true> const_iterator;
|
||||||
|
|
||||||
__bitset() _NOEXCEPT;
|
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
|
||||||
explicit __bitset(unsigned long long __v) _NOEXCEPT;
|
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
|
||||||
{return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
|
{return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
|
||||||
_LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
|
||||||
{return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
|
{return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
|
||||||
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
|
||||||
{return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
{return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
||||||
@ -194,8 +194,10 @@ protected:
|
|||||||
bool any() const _NOEXCEPT;
|
bool any() const _NOEXCEPT;
|
||||||
size_t __hash_code() const _NOEXCEPT;
|
size_t __hash_code() const _NOEXCEPT;
|
||||||
private:
|
private:
|
||||||
|
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
void __init(unsigned long long __v, false_type) _NOEXCEPT;
|
void __init(unsigned long long __v, false_type) _NOEXCEPT;
|
||||||
void __init(unsigned long long __v, true_type) _NOEXCEPT;
|
void __init(unsigned long long __v, true_type) _NOEXCEPT;
|
||||||
|
#endif // _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
unsigned long to_ulong(false_type) const;
|
unsigned long to_ulong(false_type) const;
|
||||||
unsigned long to_ulong(true_type) const;
|
unsigned long to_ulong(true_type) const;
|
||||||
unsigned long long to_ullong(false_type) const;
|
unsigned long long to_ullong(false_type) const;
|
||||||
@ -206,11 +208,19 @@ private:
|
|||||||
|
|
||||||
template <size_t _N_words, size_t _Size>
|
template <size_t _N_words, size_t _Size>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR
|
||||||
__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
|
__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
|
||||||
|
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
|
: __first_{0}
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
_VSTD::fill_n(__first_, _N_words, __storage_type(0));
|
_VSTD::fill_n(__first_, _N_words, __storage_type(0));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
|
|
||||||
template <size_t _N_words, size_t _Size>
|
template <size_t _N_words, size_t _Size>
|
||||||
void
|
void
|
||||||
__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
|
__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
|
||||||
@ -232,11 +242,19 @@ __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
|
|||||||
_VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
|
_VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
|
|
||||||
template <size_t _N_words, size_t _Size>
|
template <size_t _N_words, size_t _Size>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR
|
||||||
__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
|
__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
|
||||||
|
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
|
: __first_{__v}
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
|
__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t _N_words, size_t _Size>
|
template <size_t _N_words, size_t _Size>
|
||||||
@ -426,12 +444,12 @@ protected:
|
|||||||
typedef __bit_iterator<__bitset, false> iterator;
|
typedef __bit_iterator<__bitset, false> iterator;
|
||||||
typedef __bit_iterator<__bitset, true> const_iterator;
|
typedef __bit_iterator<__bitset, true> const_iterator;
|
||||||
|
|
||||||
__bitset() _NOEXCEPT;
|
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
|
||||||
explicit __bitset(unsigned long long __v) _NOEXCEPT;
|
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
|
||||||
{return reference(&__first_, __storage_type(1) << __pos);}
|
{return reference(&__first_, __storage_type(1) << __pos);}
|
||||||
_LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
|
||||||
{return const_reference(&__first_, __storage_type(1) << __pos);}
|
{return const_reference(&__first_, __storage_type(1) << __pos);}
|
||||||
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
|
||||||
{return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
{return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
||||||
@ -455,6 +473,7 @@ protected:
|
|||||||
|
|
||||||
template <size_t _Size>
|
template <size_t _Size>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR
|
||||||
__bitset<1, _Size>::__bitset() _NOEXCEPT
|
__bitset<1, _Size>::__bitset() _NOEXCEPT
|
||||||
: __first_(0)
|
: __first_(0)
|
||||||
{
|
{
|
||||||
@ -462,6 +481,7 @@ __bitset<1, _Size>::__bitset() _NOEXCEPT
|
|||||||
|
|
||||||
template <size_t _Size>
|
template <size_t _Size>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR
|
||||||
__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
|
__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
|
||||||
: __first_(static_cast<__storage_type>(__v))
|
: __first_(static_cast<__storage_type>(__v))
|
||||||
{
|
{
|
||||||
@ -567,12 +587,12 @@ protected:
|
|||||||
typedef __bit_iterator<__bitset, false> iterator;
|
typedef __bit_iterator<__bitset, false> iterator;
|
||||||
typedef __bit_iterator<__bitset, true> const_iterator;
|
typedef __bit_iterator<__bitset, true> const_iterator;
|
||||||
|
|
||||||
__bitset() _NOEXCEPT;
|
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
|
||||||
explicit __bitset(unsigned long long) _NOEXCEPT;
|
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
|
||||||
{return reference(0, 1);}
|
{return reference(0, 1);}
|
||||||
_LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t) const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
|
||||||
{return const_reference(0, 1);}
|
{return const_reference(0, 1);}
|
||||||
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
|
||||||
{return iterator(0, 0);}
|
{return iterator(0, 0);}
|
||||||
@ -595,11 +615,13 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR
|
||||||
__bitset<0, 0>::__bitset() _NOEXCEPT
|
__bitset<0, 0>::__bitset() _NOEXCEPT
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR
|
||||||
__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
|
__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -619,8 +641,9 @@ public:
|
|||||||
typedef typename base::const_reference const_reference;
|
typedef typename base::const_reference const_reference;
|
||||||
|
|
||||||
// 23.3.5.1 constructors:
|
// 23.3.5.1 constructors:
|
||||||
/*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset() _NOEXCEPT {}
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
|
||||||
/*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
||||||
|
bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
|
||||||
template<class _CharT>
|
template<class _CharT>
|
||||||
explicit bitset(const _CharT* __str,
|
explicit bitset(const _CharT* __str,
|
||||||
typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
|
typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
|
||||||
@ -647,7 +670,8 @@ public:
|
|||||||
bitset& flip(size_t __pos);
|
bitset& flip(size_t __pos);
|
||||||
|
|
||||||
// element access:
|
// element access:
|
||||||
_LIBCPP_INLINE_VISIBILITY const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
||||||
|
const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
|
||||||
_LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
|
_LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
|
||||||
unsigned long to_ulong() const;
|
unsigned long to_ulong() const;
|
||||||
unsigned long long to_ullong() const;
|
unsigned long long to_ullong() const;
|
||||||
@ -663,7 +687,7 @@ public:
|
|||||||
basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
|
basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
|
||||||
char __one = '1') const;
|
char __one = '1') const;
|
||||||
size_t count() const _NOEXCEPT;
|
size_t count() const _NOEXCEPT;
|
||||||
/*constexpr*/ _LIBCPP_INLINE_VISIBILITY size_t size() const _NOEXCEPT {return _Size;}
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
|
||||||
bool operator==(const bitset& __rhs) const _NOEXCEPT;
|
bool operator==(const bitset& __rhs) const _NOEXCEPT;
|
||||||
bool operator!=(const bitset& __rhs) const _NOEXCEPT;
|
bool operator!=(const bitset& __rhs) const _NOEXCEPT;
|
||||||
bool test(size_t __pos) const;
|
bool test(size_t __pos) const;
|
||||||
|
@ -18,7 +18,7 @@ template <std::size_t N>
|
|||||||
void test_default_ctor()
|
void test_default_ctor()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::bitset<N> v1;
|
_LIBCPP_CONSTEXPR std::bitset<N> v1;
|
||||||
assert(v1.size() == N);
|
assert(v1.size() == N);
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
assert(v1[i] == false);
|
assert(v1[i] == false);
|
||||||
|
@ -18,7 +18,7 @@ template <std::size_t N>
|
|||||||
void test_val_ctor()
|
void test_val_ctor()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
|
_LIBCPP_CONSTEXPR std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
|
||||||
assert(v.size() == N);
|
assert(v.size() == N);
|
||||||
unsigned M = std::min<std::size_t>(N, 64);
|
unsigned M = std::min<std::size_t>(N, 64);
|
||||||
for (std::size_t i = 0; i < M; ++i)
|
for (std::size_t i = 0; i < M; ++i)
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wtautological-compare"
|
||||||
|
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
void test_reset_one()
|
void test_reset_one()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user