Skip to content

Commit e95d208

Browse files
committed
Unify ULL ctor for C++03 and C++11
1 parent 1a0e03c commit e95d208

File tree

1 file changed

+11
-49
lines changed

1 file changed

+11
-49
lines changed

libcxx/include/bitset

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ protected:
229229
_LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
230230

231231
private:
232-
# ifdef _LIBCPP_CXX03_LANG
233-
void __init(unsigned long long __v, false_type) _NOEXCEPT;
234-
_LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
235-
# endif // _LIBCPP_CXX03_LANG
236232
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;
237233
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;
238234
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;
@@ -242,53 +238,20 @@ private:
242238
};
243239

244240
template <size_t _N_words, size_t _Size>
245-
inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
246-
# ifndef _LIBCPP_CXX03_LANG
247-
: __first_{0}
248-
# endif
249-
{
250-
# ifdef _LIBCPP_CXX03_LANG
251-
std::fill_n(__first_, _N_words, __storage_type(0));
252-
# endif
253-
}
254-
255-
# ifdef _LIBCPP_CXX03_LANG
241+
inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT : __first_() {}
256242

257243
template <size_t _N_words, size_t _Size>
258-
void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
259-
const size_t __n_words = std::min((sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1, _N_words);
260-
for (size_t __i = 0; __i < __n_words; ++__i, __v >>= __bits_per_word)
261-
__first_[__i] = static_cast<__storage_type>(__v);
262-
std::fill(__first_ + __n_words, __first_ + _N_words, __storage_type(0));
263-
}
244+
inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT : __first_() {
245+
_LIBCPP_CONSTEXPR size_t __ull_words = (sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1;
246+
static_assert(__ull_words <= 4, "This constructor has not been ported to this platform");
264247

265-
template <size_t _N_words, size_t _Size>
266-
inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
267248
__first_[0] = __v;
268-
std::fill(__first_ + 1, __first_ + _N_words, __storage_type(0));
269-
}
270-
271-
# endif // _LIBCPP_CXX03_LANG
272-
273-
template <size_t _N_words, size_t _Size>
274-
inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
275-
# ifndef _LIBCPP_CXX03_LANG
276-
# if __SIZEOF_SIZE_T__ == 8
277-
: __first_{__v}
278-
# elif __SIZEOF_SIZE_T__ == 4
279-
: __first_{static_cast<__storage_type>(__v),
280-
_Size >= 2 * __bits_per_word
281-
? static_cast<__storage_type>(__v >> __bits_per_word)
282-
: static_cast<__storage_type>((__v >> __bits_per_word) &
283-
(__storage_type(1) << (_Size - __bits_per_word)) - 1)}
284-
# else
285-
# error This constructor has not been ported to this platform
286-
# endif
287-
# endif
288-
{
289-
# ifdef _LIBCPP_CXX03_LANG
290-
__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
291-
# endif
249+
if _LIBCPP_CONSTEXPR (__ull_words >= 2)
250+
__first_[1] = __v >> __bits_per_word;
251+
if _LIBCPP_CONSTEXPR (__ull_words >= 3 && _N_words >= 3)
252+
__first_[2] = __v >> (2 * __bits_per_word);
253+
if _LIBCPP_CONSTEXPR (__ull_words >= 4 && _N_words >= 4)
254+
__first_[3] = __v >> (3 * __bits_per_word);
292255
}
293256

294257
template <size_t _N_words, size_t _Size>
@@ -480,8 +443,7 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
480443

481444
template <size_t _Size>
482445
inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
483-
: __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
484-
: static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
446+
: __first_(static_cast<__storage_type>(__v)) {}
485447

486448
template <size_t _Size>
487449
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void

0 commit comments

Comments
 (0)