mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
porting sscrisk/CEL
This commit is contained in:
parent
ad60c8c530
commit
db20f64991
181 changed files with 2531 additions and 607 deletions
|
@ -1,177 +0,0 @@
|
|||
#ifndef SPROUT_DETAIL_ALGORITHM_HPP
|
||||
#define SPROUT_DETAIL_ALGORITHM_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
//
|
||||
// min
|
||||
//
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR T const& min(T const& a, T const& b) {
|
||||
return b < a ? b : a;
|
||||
}
|
||||
template<typename T, typename Compare>
|
||||
SPROUT_CONSTEXPR T const& min(T const& a, T const& b, Compare comp) {
|
||||
return comp(b, a) ? b : a;
|
||||
}
|
||||
|
||||
//
|
||||
// max
|
||||
//
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR T const& max(T const& a, T const& b) {
|
||||
return a < b ? b : a;
|
||||
}
|
||||
template<typename T, typename Compare>
|
||||
SPROUT_CONSTEXPR T const& max(T const& a, T const& b, Compare comp) {
|
||||
return comp(a, b) ? b : a;
|
||||
}
|
||||
|
||||
//
|
||||
// count
|
||||
//
|
||||
template<typename InputIterator, typename T>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type count(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
T const& value
|
||||
)
|
||||
{
|
||||
return first == last
|
||||
? 0
|
||||
: (*first == value ? 1 : 0) + sprout::detail::count(sprout::next(first), last, value)
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// count_if
|
||||
//
|
||||
template<typename InputIterator, typename Predicate>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type count_if(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Predicate pred
|
||||
)
|
||||
{
|
||||
return first == last
|
||||
? 0
|
||||
: (pred(*first) ? 1 : 0) + sprout::detail::count_if(sprout::next(first), last, pred)
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// equal
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
SPROUT_CONSTEXPR bool equal(
|
||||
InputIterator1 first1,
|
||||
InputIterator1 last1,
|
||||
InputIterator2 first2
|
||||
)
|
||||
{
|
||||
return first1 == last1
|
||||
? true
|
||||
: *first1 == *first2 && sprout::detail::equal(sprout::next(first1), last1, sprout::next(first2))
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Predicate>
|
||||
SPROUT_CONSTEXPR bool equal(
|
||||
InputIterator1 first1,
|
||||
InputIterator1 last1,
|
||||
InputIterator2 first2,
|
||||
Predicate pred
|
||||
)
|
||||
{
|
||||
return first1 == last1
|
||||
? true
|
||||
: pred(*first1, *first2) && sprout::detail::equal(sprout::next(first1), last1, sprout::next(first2), pred)
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// lexicographical_compare
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
SPROUT_CONSTEXPR bool lexicographical_compare(
|
||||
InputIterator1 first1,
|
||||
InputIterator1 last1,
|
||||
InputIterator2 first2,
|
||||
InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return first2 == last2
|
||||
? false
|
||||
: first1 == last1 || *first1 < *first2
|
||||
? true
|
||||
: *first2 < *first1
|
||||
? false
|
||||
: sprout::detail::lexicographical_compare(sprout::next(first1), last1, sprout::next(first2), last2)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
SPROUT_CONSTEXPR bool lexicographical_compare(
|
||||
InputIterator1 first1,
|
||||
InputIterator1 last1,
|
||||
InputIterator2 first2,
|
||||
InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
return first2 == last2
|
||||
? false
|
||||
: first1 == last1 || comp(*first1, *first2)
|
||||
? true
|
||||
: comp(*first2, *first1)
|
||||
? false
|
||||
: sprout::detail::lexicographical_compare(sprout::next(first1), last1, sprout::next(first2), last2, comp)
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// find
|
||||
//
|
||||
template<typename InputIterator, typename T>
|
||||
SPROUT_CONSTEXPR InputIterator find(InputIterator first, InputIterator last, T const& value) {
|
||||
return first == last || *first == value
|
||||
? first
|
||||
: sprout::detail::find(sprout::next(first), last, value)
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// is_sorted_until
|
||||
//
|
||||
template<typename InputIterator>
|
||||
SPROUT_CONSTEXPR InputIterator is_sorted_until(InputIterator first, InputIterator last) {
|
||||
return first == last || sprout::next(first) == last ? last
|
||||
: *sprout::next(first) < *first ? sprout::next(first)
|
||||
: sprout::detail::is_sorted_until(sprout::next(first), last)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator, typename Compare>
|
||||
SPROUT_CONSTEXPR InputIterator is_sorted_until(InputIterator first, InputIterator last, Compare comp) {
|
||||
return first == last || sprout::next(first) == last ? last
|
||||
: comp(*sprout::next(first), *first) != false ? sprout::next(first)
|
||||
: sprout::detail::is_sorted_until(sprout::next(first), last)
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// is_sorted
|
||||
//
|
||||
template<typename InputIterator>
|
||||
SPROUT_CONSTEXPR bool is_sorted(InputIterator first, InputIterator last) {
|
||||
return sprout::detail::is_sorted_until(first, last) == last;
|
||||
}
|
||||
template<typename InputIterator, typename Compare>
|
||||
SPROUT_CONSTEXPR bool is_sorted(InputIterator first, InputIterator last, Compare comp) {
|
||||
return sprout::detail::is_sorted_until(first, last, comp) == last;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_ALGORITHM_HPP
|
|
@ -1,37 +0,0 @@
|
|||
#ifndef SPROUT_DETAIL_FUNCTIONAL_HPP
|
||||
#define SPROUT_DETAIL_FUNCTIONAL_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
//
|
||||
// equal_to
|
||||
//
|
||||
template<typename T>
|
||||
class equal_to
|
||||
: public std::binary_function<T, T, bool>
|
||||
{
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const {
|
||||
return lhs == rhs;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// less
|
||||
//
|
||||
template<typename T>
|
||||
class less
|
||||
: public std::binary_function<T, T, bool>
|
||||
{
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const {
|
||||
return lhs < rhs;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_FUNCTIONAL_HPP
|
|
@ -1,76 +0,0 @@
|
|||
#ifndef SPROUT_DETAIL_ITERATOR_HPP
|
||||
#define SPROUT_DETAIL_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
namespace detail_ {
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type distance(
|
||||
Iterator first,
|
||||
Iterator last
|
||||
)
|
||||
{
|
||||
return first == last
|
||||
? 0
|
||||
: 1 + sprout::detail::detail_::distance(sprout::next(first), last)
|
||||
;
|
||||
}
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type distance_impl(
|
||||
Iterator first,
|
||||
Iterator last
|
||||
)
|
||||
{
|
||||
using sprout::detail::detail_::distance;
|
||||
return distance(first, last);
|
||||
}
|
||||
} // namespace detail_
|
||||
//
|
||||
// distance
|
||||
//
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type distance(
|
||||
Iterator first,
|
||||
Iterator last
|
||||
)
|
||||
{
|
||||
return sprout::detail::detail_::distance_impl(first, last);
|
||||
}
|
||||
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type bidirectional_distance_impl(
|
||||
Iterator first1,
|
||||
Iterator first2,
|
||||
Iterator last,
|
||||
typename std::iterator_traits<Iterator>::difference_type current = 1
|
||||
)
|
||||
{
|
||||
return first1 == last
|
||||
? current
|
||||
: first2 == last
|
||||
? -current
|
||||
: sprout::detail::bidirectional_distance_impl(sprout::next(first1), sprout::prev(first2), last, current + 1)
|
||||
;
|
||||
}
|
||||
//
|
||||
// bidirectional_distance
|
||||
//
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type bidirectional_distance(
|
||||
Iterator first,
|
||||
Iterator last
|
||||
)
|
||||
{
|
||||
return first == last
|
||||
? 0
|
||||
: sprout::detail::bidirectional_distance_impl(sprout::next(first), sprout::prev(first), last)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_ITERATOR_HPP
|
40
sprout/detail/iterator_ext.hpp
Normal file
40
sprout/detail/iterator_ext.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef SPROUT_DETAIL_ITERATOR_EXT_HPP
|
||||
#define SPROUT_DETAIL_ITERATOR_EXT_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type bidirectional_distance_impl(
|
||||
Iterator first1,
|
||||
Iterator first2,
|
||||
Iterator last,
|
||||
typename std::iterator_traits<Iterator>::difference_type current = 1
|
||||
)
|
||||
{
|
||||
return first1 == last ? current
|
||||
: first2 == last ? -current
|
||||
: sprout::detail::bidirectional_distance_impl(sprout::next(first1), sprout::prev(first2), last, current + 1)
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// bidirectional_distance
|
||||
//
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type bidirectional_distance(
|
||||
Iterator first,
|
||||
Iterator last
|
||||
)
|
||||
{
|
||||
return first == last ? 0
|
||||
: sprout::detail::bidirectional_distance_impl(sprout::next(first), sprout::prev(first), last)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_ITERATOR_EXT_HPP
|
Loading…
Add table
Add a link
Reference in a new issue