Skip to content

Commit cf0d4d7

Browse files
committed
Unify ULL ctor for C++03 and C++11
1 parent ab71772 commit cf0d4d7

File tree

1 file changed

+16
-48
lines changed

1 file changed

+16
-48
lines changed

libcxx/include/bitset

Lines changed: 16 additions & 48 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,52 +238,25 @@ 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
256-
257-
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-
}
241+
inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT : __first_() {}
264242

265243
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 {
244+
inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT : __first_() {
267245
__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
246+
# if (__SIZEOF_LONG_LONG__ - 1) / __SIZEOF_SIZE_T__ + 1 == 1
247+
// No additional assignments needed for __first_ array
248+
# elif (__SIZEOF_LONG_LONG__ - 1) / __SIZEOF_SIZE_T__ + 1 == 2
249+
__first_[1] = __v >> __bits_per_word;
250+
# elif (__SIZEOF_LONG_LONG__ - 1) / __SIZEOF_SIZE_T__ + 1 == 4
251+
__first_[1] = __v >> __bits_per_word;
252+
# if _N_words >= 3
253+
__first_[2] = __v >> (2 * __bits_per_word);
286254
# endif
287-
# endif
288-
{
289-
# ifdef _LIBCPP_CXX03_LANG
290-
__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
255+
# if _N_words >= 4
256+
__first_[3] = __v >> (3 * __bits_per_word);
257+
# endif
258+
# else
259+
# error This constructor has not been ported to this platform
291260
# endif
292261
}
293262

@@ -480,8 +449,7 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
480449

481450
template <size_t _Size>
482451
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)) {}
452+
: __first_(static_cast<__storage_type>(__v)) {}
485453

486454
template <size_t _Size>
487455
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void

0 commit comments

Comments
 (0)