mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-16 15:14:13 +00:00
fix: random generator/distribution result type (add const)
This commit is contained in:
parent
1132d08f23
commit
2c9f0647f4
33 changed files with 342 additions and 123 deletions
|
@ -41,5 +41,30 @@
|
|||
#include <sprout/algorithm/cxx14/partition.hpp>
|
||||
#include <sprout/algorithm/cxx14/stable_partition.hpp>
|
||||
#include <sprout/algorithm/cxx14/partition_copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/sort.hpp>
|
||||
#include <sprout/algorithm/cxx14/stable_sort.hpp>
|
||||
#include <sprout/algorithm/cxx14/partial_sort.hpp>
|
||||
#include <sprout/algorithm/cxx14/partial_sort_copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/nth_element.hpp>
|
||||
//#include <sprout/algorithm/cxx14/merge.hpp>
|
||||
//#include <sprout/algorithm/cxx14/inplace_merge.hpp>
|
||||
//#include <sprout/algorithm/cxx14/set_union.hpp>
|
||||
//#include <sprout/algorithm/cxx14/set_intersection.hpp>
|
||||
//#include <sprout/algorithm/cxx14/set_difference.hpp>
|
||||
//#include <sprout/algorithm/cxx14/set_symmetric_difference.hpp>
|
||||
//#include <sprout/algorithm/cxx14/push_heap.hpp>
|
||||
//#include <sprout/algorithm/cxx14/pop_heap.hpp>
|
||||
//#include <sprout/algorithm/cxx14/make_heap.hpp>
|
||||
//#include <sprout/algorithm/cxx14/sort_heap.hpp>
|
||||
//#include <sprout/algorithm/cxx14/next_permutation.hpp>
|
||||
//#include <sprout/algorithm/cxx14/prev_permutation.hpp>
|
||||
//#include <sprout/algorithm/cxx14/copy_while.hpp>
|
||||
//#include <sprout/algorithm/cxx14/copy_until.hpp>
|
||||
//#include <sprout/algorithm/cxx14/clamp_range.hpp>
|
||||
//#include <sprout/algorithm/cxx14/clamp_range_copy.hpp>
|
||||
//#include <sprout/algorithm/cxx14/bogo_sort.hpp>
|
||||
//#include <sprout/algorithm/cxx14/bogo_sort_result.hpp>
|
||||
//#include <sprout/algorithm/cxx14/bozo_sort.hpp>
|
||||
//#include <sprout/algorithm/cxx14/bozo_sort_result.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_CXX14_HPP
|
||||
|
|
27
sprout/algorithm/cxx14/nth_element.hpp
Normal file
27
sprout/algorithm/cxx14/nth_element.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_CXX14_ALGORITHM_NTH_ELEMENT_HPP
|
||||
#define SPROUT_CXX14_ALGORITHM_NTH_ELEMENT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.4.2 Nth element
|
||||
//
|
||||
// !!! TOTO: implementation
|
||||
template<typename RandomAccessIterator>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
|
||||
|
||||
template<typename RandomAccessIterator, typename Compare>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_NTH_ELEMENT_HPP
|
27
sprout/algorithm/cxx14/partial_sort.hpp
Normal file
27
sprout/algorithm/cxx14/partial_sort.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_CXX14_ALGORITHM_PARTIAL_SORT_HPP
|
||||
#define SPROUT_CXX14_ALGORITHM_PARTIAL_SORT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.4.1.3 partial_sort
|
||||
//
|
||||
// !!! TOTO: implementation
|
||||
template<typename RandomAccessIterator>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
|
||||
|
||||
template<typename RandomAccessIterator, typename Compare>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_PARTIAL_SORT_HPP
|
27
sprout/algorithm/cxx14/partial_sort_copy.hpp
Normal file
27
sprout/algorithm/cxx14/partial_sort_copy.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_CXX14_ALGORITHM_PARTIAL_SORT_COPY_HPP
|
||||
#define SPROUT_CXX14_ALGORITHM_PARTIAL_SORT_COPY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.4.1.4 partial_sort_copy
|
||||
//
|
||||
// !!! TOTO: implementation
|
||||
template<typename InputIterator, typename RandomAccessIterator>
|
||||
inline SPROUT_CXX14_CONSTEXPR RandomAccessIterator
|
||||
partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last);
|
||||
|
||||
template<typename InputIterator, typename RandomAccessIterator, typename Compare>
|
||||
inline SPROUT_CXX14_CONSTEXPR RandomAccessIterator
|
||||
partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_PARTIAL_SORT_COPY_HPP
|
|
@ -17,7 +17,16 @@ namespace sprout {
|
|||
//
|
||||
template<typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate>
|
||||
inline SPROUT_CXX14_CONSTEXPR sprout::pair<OutputIterator1, OutputIterator2>
|
||||
partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred); // !!!
|
||||
partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred) {
|
||||
for (; first != last; ++first) {
|
||||
if (p(*first)) {
|
||||
*out_true++ = *first;
|
||||
} else {
|
||||
*out_false++ = *first;
|
||||
}
|
||||
}
|
||||
return sprout::pair<OutputIterator1, OutputIterator2>(out_true, out_false);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_PARTITION_COPY_HPP
|
||||
|
|
|
@ -8,7 +8,11 @@
|
|||
#ifndef SPROUT_CXX14_ALGORITHM_SHUFFLE_HPP
|
||||
#define SPROUT_CXX14_ALGORITHM_SHUFFLE_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/algorithm/cxx14/iter_swap.hpp>
|
||||
#include <sprout/workaround/detail/uniform_int_distribution.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -16,7 +20,20 @@ namespace sprout {
|
|||
//
|
||||
template<typename RandomAccessIterator, typename UniformRandomNumberGenerator>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
shuffle(RandomAccessIterator first, RandomAccessIterator last, UniformRandomNumberGenerator&& g); // !!!
|
||||
shuffle(RandomAccessIterator first, RandomAccessIterator last, UniformRandomNumberGenerator&& g) {
|
||||
typedef typename std::iterator_traits<RandomAccessIterator>::difference_type difference_type;
|
||||
typedef SPROUT_WORKAROUND_DETAIL_UNIFORM_INT_DISTRIBUTION<std::ptrdiff_t> distribution_type;
|
||||
typedef typename distribution_type::param_type param_type;
|
||||
difference_type d = last - first;
|
||||
if (d > 1) {
|
||||
distribution_type dist;
|
||||
for (--last, --d; first < last; ++first, --d) {
|
||||
difference_type i = dist(g, param_type(0, d));
|
||||
if (i != difference_type(0))
|
||||
sprout::iter_swap(first, first + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_SHUFFLE_HPP
|
||||
|
|
27
sprout/algorithm/cxx14/sort.hpp
Normal file
27
sprout/algorithm/cxx14/sort.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_CXX14_ALGORITHM_SORT_HPP
|
||||
#define SPROUT_CXX14_ALGORITHM_SORT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.4.1.1 sort
|
||||
//
|
||||
// !!! TOTO: implementation
|
||||
template<typename RandomAccessIterator>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
sort(RandomAccessIterator first, RandomAccessIterator last);
|
||||
|
||||
template<typename RandomAccessIterator, typename Compare>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_SORT_HPP
|
|
@ -14,9 +14,10 @@ namespace sprout {
|
|||
//
|
||||
// 25.3.13 Partitions
|
||||
//
|
||||
// !!! TOTO: implementation
|
||||
template<typename BidirectionalIterator, typename Predicate>
|
||||
inline SPROUT_CXX14_CONSTEXPR BidirectionalIterator
|
||||
stable_partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred); // !!!
|
||||
stable_partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_STABLE_PARTITION_HPP
|
||||
|
|
27
sprout/algorithm/cxx14/stable_sort.hpp
Normal file
27
sprout/algorithm/cxx14/stable_sort.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_CXX14_ALGORITHM_STABLE_SORT_HPP
|
||||
#define SPROUT_CXX14_ALGORITHM_STABLE_SORT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.4.1.2 stable_sort
|
||||
//
|
||||
// !!! TOTO: implementation
|
||||
template<typename RandomAccessIterator>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
stable_sort(RandomAccessIterator first, RandomAccessIterator last);
|
||||
|
||||
template<typename RandomAccessIterator, typename Compare>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CXX14_ALGORITHM_STABLE_SORT_HPP
|
|
@ -11,5 +11,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/fixed/nth_element.hpp>
|
||||
#include <sprout/algorithm/fit/nth_element.hpp>
|
||||
#include <sprout/algorithm/cxx14/nth_element.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_NTH_ELEMENT_HPP
|
||||
|
|
|
@ -11,5 +11,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/fixed/partial_sort.hpp>
|
||||
#include <sprout/algorithm/fit/partial_sort.hpp>
|
||||
#include <sprout/algorithm/cxx14/partial_sort.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_PARTIAL_SORT_HPP
|
||||
|
|
14
sprout/algorithm/partial_sort_copy.hpp
Normal file
14
sprout/algorithm/partial_sort_copy.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_ALGORITHM_PARTIAL_SORT_COPY_HPP
|
||||
#define SPROUT_ALGORITHM_PARTIAL_SORT_COPY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/cxx14/partial_sort_copy.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_PARTIAL_SORT_COPY_HPP
|
|
@ -11,5 +11,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/fixed/sort.hpp>
|
||||
#include <sprout/algorithm/fit/sort.hpp>
|
||||
#include <sprout/algorithm/cxx14/sort.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_SORT_HPP
|
||||
|
|
|
@ -11,5 +11,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/fixed/stable_sort.hpp>
|
||||
#include <sprout/algorithm/fit/stable_sort.hpp>
|
||||
#include <sprout/algorithm/cxx14/stable_sort.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_STABLE_SORT_HPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue