mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-01-23 20:46:37 +00:00
add c++14 constexpr version: transform, replace
This commit is contained in:
parent
a3427d375f
commit
3f85600f53
11 changed files with 154 additions and 73 deletions
|
@ -9,10 +9,8 @@
|
|||
#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>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -29,21 +27,6 @@ namespace sprout {
|
|||
}
|
||||
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>
|
||||
|
|
|
@ -9,10 +9,8 @@
|
|||
#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>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -29,21 +27,6 @@ namespace sprout {
|
|||
}
|
||||
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>
|
||||
|
|
|
@ -9,10 +9,8 @@
|
|||
#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>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -31,21 +29,6 @@ namespace sprout {
|
|||
}
|
||||
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>
|
||||
|
|
|
@ -9,10 +9,8 @@
|
|||
#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>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -29,21 +27,6 @@ namespace sprout {
|
|||
}
|
||||
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>
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/container/indexes.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit/pit.hpp>
|
||||
#include <sprout/math/less.hpp>
|
||||
|
@ -134,6 +136,21 @@ namespace sprout {
|
|||
return sprout::fixed::copy(first, last, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
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
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_HPP
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/container/indexes.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit/pit.hpp>
|
||||
#include <sprout/math/greater_equal.hpp>
|
||||
|
@ -124,6 +126,21 @@ namespace sprout {
|
|||
return sprout::fixed::copy_backward(first, last, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
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
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_BACKWARD_HPP
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/filter_iterator.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit/pit.hpp>
|
||||
#include <sprout/detail/container_complate.hpp>
|
||||
|
@ -89,6 +91,21 @@ namespace sprout {
|
|||
return sprout::fixed::copy_if(first, last, sprout::pit<Result>(), pred);
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
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
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_IF_HPP
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
#include <sprout/pit/pit.hpp>
|
||||
|
@ -107,6 +109,21 @@ namespace sprout {
|
|||
return sprout::fixed::copy_n(first, n, sprout::pit<Result>());
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
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
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_COPY_N_HPP
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit/pit.hpp>
|
||||
#include <sprout/detail/container_complate.hpp>
|
||||
|
@ -260,7 +262,39 @@ namespace sprout {
|
|||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::transform;
|
||||
template<
|
||||
typename InputIterator, typename Result, typename UnaryOperation,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
transform(InputIterator first, InputIterator last, Result const& result, UnaryOperation op) {
|
||||
return sprout::fixed::transform(first, last, result, op);
|
||||
}
|
||||
template<
|
||||
typename Result, typename InputIterator, typename UnaryOperation,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
transform(InputIterator first, InputIterator last, UnaryOperation op) {
|
||||
return sprout::fixed::transform<Result>(first, last, op);
|
||||
}
|
||||
|
||||
template<
|
||||
typename InputIterator1, typename InputIterator2, typename Result, typename BinaryOperation,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, Result const& result, BinaryOperation op) {
|
||||
return sprout::fixed::transform(first1, last1, first2, result, op);
|
||||
}
|
||||
template<
|
||||
typename Result, typename InputIterator1, typename InputIterator2, typename BinaryOperation,
|
||||
typename sprout::enabler_if<!sprout::is_output_iterator<Result>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryOperation op) {
|
||||
return sprout::fixed::transform<Result>(first1, last1, first2, op);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIXED_TRANSFORM_HPP
|
||||
|
|
|
@ -9,6 +9,22 @@
|
|||
#define SPROUT_ALGORITHM_REPLACE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.5 Replace
|
||||
//
|
||||
template<typename ForwrdIterator, typename T>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
replace(ForwrdIterator first, ForwrdIterator last, T const& old_value, T const& new_value) {
|
||||
for (; first != last; ++first) {
|
||||
if (*first == old_value) {
|
||||
*first = new_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/replace.hpp>
|
||||
#include <sprout/algorithm/fit/replace.hpp>
|
||||
|
||||
|
|
|
@ -9,6 +9,37 @@
|
|||
#define SPROUT_ALGORITHM_TRANSFORM_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// 25.3.4 Transform
|
||||
//
|
||||
template<
|
||||
typename InputIterator, typename OutputIterator, typename UnaryOperation,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op) {
|
||||
while (first != last) {
|
||||
*result++ = op(*first++);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
template<
|
||||
typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperation,
|
||||
typename sprout::enabler_if<sprout::is_output_iterator<OutputIterator>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperation op) {
|
||||
while (first1 != last1) {
|
||||
*result++ = op(*first1++, *first2++);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/algorithm/fit/transform.hpp>
|
||||
|
||||
|
|
Loading…
Reference in a new issue