123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- #ifndef __BOOST_SORT_COMMON_UTIL_ALGORITHM_HPP
- #define __BOOST_SORT_COMMON_UTIL_ALGORITHM_HPP
- #include <ciso646>
- #include <algorithm>
- #include <functional>
- #include <iterator>
- #include <memory>
- #include <type_traits>
- #include <vector>
- #include <boost/sort/common/util/traits.hpp>
- namespace boost
- {
- namespace sort
- {
- namespace common
- {
- namespace util
- {
- static constexpr const uint32_t tmsb[256] =
- { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
- static inline uint32_t nbits32 (uint32_t num) noexcept
- {
- int Pos = (num & 0xffff0000U) ? 16 : 0;
- if ((num >> Pos) & 0xff00U) Pos += 8;
- return (tmsb[num >> Pos] + Pos);
- }
- static inline uint32_t nbits64(uint64_t num)noexcept
- {
- uint32_t Pos = (num & 0xffffffff00000000ULL) ? 32 : 0;
- if ((num >> Pos) & 0xffff0000ULL) Pos += 16;
- if ((num >> Pos) & 0xff00ULL) Pos += 8;
- return (tmsb[num >> Pos] + Pos);
- }
- template <class Value_t, class ... Args>
- inline void construct_object (Value_t *ptr, Args &&... args)
- {
- (::new (static_cast<void *>(ptr)) Value_t(std::forward< Args > (args)...));
- };
- template<class Value_t>
- inline void destroy_object(Value_t *ptr)
- {
- ptr->~Value_t();
- };
- template <class Iter_t, class Value_t = value_iter<Iter_t> >
- inline void initialize (Iter_t first, Iter_t last, Value_t & val)
- {
-
-
-
- typedef value_iter<Iter_t> value_t;
- static_assert (std::is_same< Value_t, value_t >::value,
- "Incompatible iterators\n");
-
-
-
- if (first == last) return;
- construct_object(&(*first), std::move(val));
- Iter_t it1 = first, it2 = first + 1;
- while (it2 != last)
- {
- construct_object(&(*(it2++)), std::move(*(it1++)));
- };
- val = std::move(*(last - 1));
- };
- template <class Iter1_t, class Iter2_t>
- inline Iter2_t move_forward (Iter2_t it_dest, Iter1_t first, Iter1_t last)
- {
-
-
-
- typedef value_iter<Iter1_t> value1_t;
- typedef value_iter<Iter2_t> value2_t;
- static_assert (std::is_same< value1_t, value2_t >::value,
- "Incompatible iterators\n");
-
-
-
- while (first != last)
- { *it_dest++ = std::move(*first++);
- }
- return it_dest;
- };
- template<class Iter1_t, class Iter2_t>
- inline Iter2_t move_backward(Iter2_t it_dest, Iter1_t first, Iter1_t last)
- {
-
-
-
- typedef value_iter<Iter1_t> value1_t;
- typedef value_iter<Iter2_t> value2_t;
- static_assert (std::is_same< value1_t, value2_t >::value,
- "Incompatible iterators\n");
-
-
-
- while (first != last)
- { *(--it_dest) = std::move (*(--last));
- }
- return it_dest;
- };
- template<class Iter_t, class Value_t = value_iter<Iter_t> >
- inline Value_t * move_construct(Value_t *ptr, Iter_t first, Iter_t last)
- {
-
-
-
- typedef typename iterator_traits<Iter_t>::value_type value2_t;
- static_assert (std::is_same< Value_t, value2_t >::value,
- "Incompatible iterators\n");
-
-
-
- while (first != last)
- {
- ::new (static_cast<void *>(ptr++)) Value_t(std::move(*(first++)));
- };
- return ptr;
- };
- template<class Iter_t>
- inline void destroy(Iter_t first, const Iter_t last)
- {
- while (first != last)
- destroy_object(&(*(first++)));
- };
- template<class Iter_t>
- inline void reverse(Iter_t first, Iter_t last)
- {
- std::reverse ( first, last);
- };
- };
- };
- };
- };
- #endif
|