mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-02 14:04:20 +00:00
add constexpr algorithm C++14 version: move, move_backward, swap_ranges, iter_swap
This commit is contained in:
parent
d5c84b07c9
commit
a3427d375f
23 changed files with 430 additions and 47 deletions
|
@ -9,6 +9,43 @@
|
|||
#define SPROUT_ALGORITHM_COPY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
copy(InputIterator first, InputIterator last, OutputIterator result) {
|
||||
while (first != last) {
|
||||
*result++ = *first++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename InputIterator, typename Result,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy(InputIterator first, InputIterator last, Result const& result) {
|
||||
return sprout::fixed::copy(first, last, result);
|
||||
}
|
||||
|
||||
template<typename Result, typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy(InputIterator first, InputIterator last) {
|
||||
return sprout::fixed::copy<Result>(first, last);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
#include <sprout/algorithm/fit/copy.hpp>
|
||||
|
||||
|
|
|
@ -9,6 +9,43 @@
|
|||
#define SPROUT_ALGORITHM_COPY_BACKWARD_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename BidirectionalIterator1, typename BidirectionalIterator2,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<BidirectionalIterator2>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR BidirectionalIterator2
|
||||
copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result) {
|
||||
while (first != last) {
|
||||
*--result = *--first;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename BidirectionalIterator, typename Result,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_backward(BidirectionalIterator first, BidirectionalIterator last, Result const& result) {
|
||||
return sprout::fixed::copy_backward(first, last, result);
|
||||
}
|
||||
|
||||
template<typename Result, typename BidirectionalIterator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_backward(BidirectionalIterator first, BidirectionalIterator last) {
|
||||
return sprout::fixed::copy_backward<Result>(first, last);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
#include <sprout/algorithm/fit/copy_backward.hpp>
|
||||
|
||||
|
|
|
@ -9,6 +9,45 @@
|
|||
#define SPROUT_ALGORITHM_COPY_IF_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator, typename Predicate,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred) {
|
||||
for (; first != last; ++first) {
|
||||
if (pred(*first)) {
|
||||
*result++ = *first;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename InputIterator, typename Result, typename Predicate,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_if(InputIterator first, InputIterator last, Result const& result, Predicate pred) {
|
||||
return sprout::fixed::copy_if(first, last, result, pred);
|
||||
}
|
||||
|
||||
template<typename Result, typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_if(InputIterator first, InputIterator last, Predicate pred) {
|
||||
return sprout::fixed::copy_if<Result>(first, last, pred);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy_if.hpp>
|
||||
#include <sprout/algorithm/fit/copy_if.hpp>
|
||||
|
||||
|
|
|
@ -9,6 +9,43 @@
|
|||
#define SPROUT_ALGORITHM_COPY_N_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy_n.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.1 Copy
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename Size, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
copy_n(InputIterator first, Size n, OutputIterator result) {
|
||||
for (Size i = 0; i < n; ++i) {
|
||||
*result++ = *first++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<
|
||||
typename InputIterator, typename Size, typename Result,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_n(InputIterator first, Size n, Result const& result) {
|
||||
return sprout::fixed::copy_n(first, n, result);
|
||||
}
|
||||
|
||||
template<typename Result, typename Size, typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
copy_n(InputIterator first, Size n) {
|
||||
return sprout::fixed::copy_n<Result>(first, n);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/copy_n.hpp>
|
||||
#include <sprout/algorithm/fit/copy_n.hpp>
|
||||
|
||||
|
|
|
@ -134,8 +134,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy(first, last, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_HPP
|
||||
|
|
|
@ -124,8 +124,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy_backward(first, last, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy_backward;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_BACKWARD_HPP
|
||||
|
|
|
@ -89,8 +89,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy_if(first, last, sprout::pit<Result>(), pred);
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy_if;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_IF_HPP
|
||||
|
|
|
@ -107,8 +107,6 @@ namespace sprout {
|
|||
return sprout::fixed::copy_n(first, n, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::copy_n;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_N_HPP
|
||||
|
|
25
sprout/algorithm/iter_swap.hpp
Normal file
25
sprout/algorithm/iter_swap.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*=============================================================================
|
||||
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_ITER_SWAP_HPP
|
||||
#define SPROUT_ALGORITHM_ITER_SWAP_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.3 swap
|
||||
//
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
iter_swap(ForwardIterator1 a, ForwardIterator2 b) {
|
||||
sprout::swap(*a, *b);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_ITER_SWAP_HPP
|
|
@ -9,7 +9,71 @@
|
|||
#define SPROUT_ALGORITHM_MODIFYIING_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/fixed.hpp>
|
||||
#include <sprout/algorithm/fit.hpp>
|
||||
#include <sprout/algorithm/copy.hpp>
|
||||
#include <sprout/algorithm/copy_n.hpp>
|
||||
#include <sprout/algorithm/copy_if.hpp>
|
||||
#include <sprout/algorithm/copy_backward.hpp>
|
||||
#include <sprout/algorithm/move.hpp>
|
||||
#include <sprout/algorithm/move_backward.hpp>
|
||||
#include <sprout/algorithm/swap_ranges.hpp>
|
||||
#include <sprout/algorithm/iter_swap.hpp>
|
||||
#include <sprout/algorithm/transform.hpp>
|
||||
#include <sprout/algorithm/replace.hpp>
|
||||
#include <sprout/algorithm/replace_if.hpp>
|
||||
#include <sprout/algorithm/replace_copy.hpp>
|
||||
#include <sprout/algorithm/replace_copy_if.hpp>
|
||||
#include <sprout/algorithm/fill.hpp>
|
||||
#include <sprout/algorithm/fill_n.hpp>
|
||||
#include <sprout/algorithm/generate.hpp>
|
||||
#include <sprout/algorithm/generate_n.hpp>
|
||||
#include <sprout/algorithm/unfold.hpp>
|
||||
#include <sprout/algorithm/unfold_n.hpp>
|
||||
#include <sprout/algorithm/recurrence.hpp>
|
||||
#include <sprout/algorithm/recurrence_n.hpp>
|
||||
#include <sprout/algorithm/remove.hpp>
|
||||
#include <sprout/algorithm/remove_if.hpp>
|
||||
#include <sprout/algorithm/remove_copy.hpp>
|
||||
#include <sprout/algorithm/remove_copy_if.hpp>
|
||||
#include <sprout/algorithm/unique.hpp>
|
||||
#include <sprout/algorithm/unique_copy.hpp>
|
||||
#include <sprout/algorithm/reverse.hpp>
|
||||
#include <sprout/algorithm/reverse_copy.hpp>
|
||||
#include <sprout/algorithm/rotate.hpp>
|
||||
#include <sprout/algorithm/rotate_copy.hpp>
|
||||
#include <sprout/algorithm/shuffle.hpp>
|
||||
#include <sprout/algorithm/shuffle_result.hpp>
|
||||
#include <sprout/algorithm/partition.hpp>
|
||||
#include <sprout/algorithm/partition_copy.hpp>
|
||||
#include <sprout/algorithm/stable_partition.hpp>
|
||||
#include <sprout/algorithm/stable_partition_copy.hpp>
|
||||
#include <sprout/algorithm/sort.hpp>
|
||||
#include <sprout/algorithm/stable_sort.hpp>
|
||||
#include <sprout/algorithm/partial_sort.hpp>
|
||||
#include <sprout/algorithm/nth_element.hpp>
|
||||
#include <sprout/algorithm/merge.hpp>
|
||||
#include <sprout/algorithm/inplace_merge.hpp>
|
||||
#include <sprout/algorithm/set_union.hpp>
|
||||
#include <sprout/algorithm/set_intersection.hpp>
|
||||
#include <sprout/algorithm/set_difference.hpp>
|
||||
#include <sprout/algorithm/set_symmetric_difference.hpp>
|
||||
#include <sprout/algorithm/push_heap.hpp>
|
||||
#include <sprout/algorithm/pop_heap.hpp>
|
||||
#include <sprout/algorithm/make_heap.hpp>
|
||||
#include <sprout/algorithm/make_partial_heap.hpp>
|
||||
#include <sprout/algorithm/sort_heap.hpp>
|
||||
#include <sprout/algorithm/next_permutation.hpp>
|
||||
#include <sprout/algorithm/prev_permutation.hpp>
|
||||
#include <sprout/algorithm/copy_while.hpp>
|
||||
#include <sprout/algorithm/copy_until.hpp>
|
||||
#include <sprout/algorithm/clamp_range.hpp>
|
||||
#include <sprout/algorithm/clamp_range_copy.hpp>
|
||||
#include <sprout/algorithm/swap_element.hpp>
|
||||
#include <sprout/algorithm/swap_element_copy.hpp>
|
||||
#include <sprout/algorithm/random_swap.hpp>
|
||||
#include <sprout/algorithm/random_swap_result.hpp>
|
||||
#include <sprout/algorithm/bogo_sort.hpp>
|
||||
#include <sprout/algorithm/bogo_sort_result.hpp>
|
||||
#include <sprout/algorithm/bozo_sort.hpp>
|
||||
#include <sprout/algorithm/bozo_sort_result.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_MODIFYIING_HPP
|
||||
|
|
33
sprout/algorithm/move.hpp
Normal file
33
sprout/algorithm/move.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*=============================================================================
|
||||
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_MOVE_HPP
|
||||
#define SPROUT_ALGORITHM_MOVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.2 Move
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
move(InputIterator first, InputIterator last, OutputIterator result) {
|
||||
while (first != last) {
|
||||
*result++ = sprout::move(*first++);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_MOVE_HPP
|
33
sprout/algorithm/move_backward.hpp
Normal file
33
sprout/algorithm/move_backward.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*=============================================================================
|
||||
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_MOVE_BACKWARD_HPP
|
||||
#define SPROUT_ALGORITHM_MOVE_BACKWARD_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.2 Move
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
move_backward(InputIterator first, InputIterator last, OutputIterator result) {
|
||||
while (first != last) {
|
||||
*--result = sprout::move(*--first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_MOVE_BACKWARD_HPP
|
28
sprout/algorithm/swap_ranges.hpp
Normal file
28
sprout/algorithm/swap_ranges.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*=============================================================================
|
||||
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_SWAP_RANGES_HPP
|
||||
#define SPROUT_ALGORITHM_SWAP_RANGES_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/iter_swap.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.3 swap
|
||||
//
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CXX14_CONSTEXPR ForwardIterator2
|
||||
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) {
|
||||
while (first1 != last1) {
|
||||
sprout::iter_swap(*first1++, *first2++);
|
||||
}
|
||||
return first2;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_SWAP_RANGES_HPP
|
Loading…
Add table
Add a link
Reference in a new issue