mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-14 10:39:05 +00:00
add algorithm for_each, gather
This commit is contained in:
parent
bbc67ea04a
commit
71144902ff
6 changed files with 125 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#define SPROUT_ALGORITHM_CXX14_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/cxx14/for_each.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy_n.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy_if.hpp>
|
||||
|
@ -62,6 +63,7 @@
|
|||
#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/gather.hpp>
|
||||
#include <sprout/algorithm/cxx14/random_swap.hpp>
|
||||
#include <sprout/algorithm/cxx14/bogo_sort.hpp>
|
||||
#include <sprout/algorithm/cxx14/bozo_sort.hpp>
|
||||
|
|
28
sprout/algorithm/cxx14/for_each.hpp
Normal file
28
sprout/algorithm/cxx14/for_each.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 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_CXX14_FOR_EACH_HPP
|
||||
#define SPROUT_ALGORITHM_CXX14_FOR_EACH_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.2.4 For each
|
||||
//
|
||||
template<typename InputIterator, typename Function>
|
||||
inline SPROUT_CXX14_CONSTEXPR Function
|
||||
for_each(InputIterator first, InputIterator last, Function f) {
|
||||
for (; first != last; ++first) {
|
||||
f(*first);
|
||||
}
|
||||
return sprout::move(f);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_CXX14_FOR_EACH_HPP
|
30
sprout/algorithm/cxx14/gather.hpp
Normal file
30
sprout/algorithm/cxx14/gather.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 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_CXX14_GATHER_HPP
|
||||
#define SPROUT_ALGORITHM_CXX14_GATHER_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/not1.hpp>
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include <sprout/algorithm/cxx14/stable_partition.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// gather
|
||||
//
|
||||
template<typename BidirectionalIterator, typename Predicate>
|
||||
inline SPROUT_CXX14_CONSTEXPR sprout::pair<BidirectionalIterator, BidirectionalIterator>
|
||||
gather(BidirectionalIterator first, BidirectionalIterator last, BidirectionalIterator pivot, Predicate pred) {
|
||||
return sprout::pair<BidirectionalIterator, BidirectionalIterator>(
|
||||
sprout::stable_partition(first, pivot, sprout::not1(pred)),
|
||||
sprout::stable_partition(pivot, last, pred)
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_CXX14_GATHER_HPP
|
|
@ -9,6 +9,7 @@
|
|||
#define SPROUT_RANGE_ALGORITHM_CXX14_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/for_each.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/copy_if.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/copy_backward.hpp>
|
||||
|
@ -58,6 +59,7 @@
|
|||
#include <sprout/range/algorithm/cxx14/copy_while.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/copy_until.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/clamp_range.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/gather.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/random_swap.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/bogo_sort.hpp>
|
||||
#include <sprout/range/algorithm/cxx14/bozo_sort.hpp>
|
||||
|
|
28
sprout/range/algorithm/cxx14/for_each.hpp
Normal file
28
sprout/range/algorithm/cxx14/for_each.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 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_RANGE_ALGORITHM_CXX14_FOR_EACH_HPP
|
||||
#define SPROUT_RANGE_ALGORITHM_CXX14_FOR_EACH_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/algorithm/cxx14/for_each.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace range {
|
||||
//
|
||||
// for_each
|
||||
//
|
||||
template<typename InputRange, typename Function>
|
||||
inline SPROUT_CXX14_CONSTEXPR Function
|
||||
for_each(InputRange&& rng, Function f) {
|
||||
return sprout::for_each(sprout::begin(SPROUT_FORWARD(InputRange, rng)), sprout::end(SPROUT_FORWARD(InputRange, rng)), f);
|
||||
}
|
||||
} // namespace range
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ALGORITHM_CXX14_FOR_EACH_HPP
|
35
sprout/range/algorithm/cxx14/gather.hpp
Normal file
35
sprout/range/algorithm/cxx14/gather.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 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_RANGE_ALGORITHM_CXX14_GATHER_HPP
|
||||
#define SPROUT_RANGE_ALGORITHM_CXX14_GATHER_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/range_return.hpp>
|
||||
#include <sprout/algorithm/cxx14/gather.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace range {
|
||||
//
|
||||
// gather
|
||||
//
|
||||
template<typename BidirectionalRange, typename Predicate>
|
||||
inline SPROUT_CXX14_CONSTEXPR sprout::pair<
|
||||
typename sprout::range::range_return<BidirectionalRange>::type,
|
||||
typename sprout::range::range_return<BidirectionalRange>::type
|
||||
>
|
||||
gather(BidirectionalRange&& rng, typename sprout::container_traits<typename::std::remove_reference<BidirectionalRange>::type>::iterator pivot, Predicate pred) {
|
||||
return sprout::gather(sprout::begin(SPROUT_FORWARD(BidirectionalRange, rng)), sprout::end(SPROUT_FORWARD(BidirectionalRange, rng)), pivot, pred);
|
||||
}
|
||||
} // namespace range
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ALGORITHM_CXX14_GATHER_HPP
|
Loading…
Reference in a new issue