mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add adaptors::jointed
This commit is contained in:
parent
f37e8a9088
commit
e286c9bc6b
14 changed files with 907 additions and 28 deletions
|
@ -7,7 +7,7 @@
|
|||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/iterator/traits.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/range/adaptor/size_enumed.hpp>
|
||||
#include <sprout/range/algorithm/lower_bound.hpp>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define SPROUT_ITERATOR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/traits.hpp>
|
||||
#include <sprout/iterator/type_traits.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/predefined.hpp>
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <sprout/iterator/filter_iterator.hpp>
|
||||
#include <sprout/iterator/indexed_iterator.hpp>
|
||||
#include <sprout/iterator/valued_iterator.hpp>
|
||||
#include <sprout/iterator/joint_iterator.hpp>
|
||||
#include <sprout/iterator/size_enum_iterator.hpp>
|
||||
#include <sprout/iterator/bytes_iterator.hpp>
|
||||
|
||||
|
|
364
sprout/iterator/joint_iterator.hpp
Normal file
364
sprout/iterator/joint_iterator.hpp
Normal file
|
@ -0,0 +1,364 @@
|
|||
#ifndef SPROUT_ITERATOR_JOINT_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_JOINT_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// joint_iterator
|
||||
//
|
||||
template<typename LIterator, typename RIterator>
|
||||
class joint_iterator
|
||||
: public std::iterator<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_value_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_difference_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_pointer<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_reference<LIterator, RIterator>::type
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef typename sprout::common_iterator_category<LIterator, RIterator>::type iterator_category;
|
||||
typedef typename sprout::common_iterator_value_type<LIterator, RIterator>::type value_type;
|
||||
typedef typename sprout::common_iterator_difference_type<LIterator, RIterator>::type difference_type;
|
||||
typedef typename sprout::common_iterator_pointer<LIterator, RIterator>::type pointer;
|
||||
typedef typename sprout::common_iterator_reference<LIterator, RIterator>::type reference;
|
||||
protected:
|
||||
iterator_type current1;
|
||||
iterator_type last1;
|
||||
iterator2_type first2;
|
||||
iterator2_type current2;
|
||||
private:
|
||||
SPROUT_CONSTEXPR joint_iterator advance_impl_posite(difference_type n, difference_type d) const {
|
||||
return n > d ? joint_iterator(last1, last1, first2, sprout::next(current2, n - d))
|
||||
: joint_iterator(sprout::next(current1, n), last1, first2, current2)
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR joint_iterator advance_impl_negate(difference_type n, difference_type d) const {
|
||||
return !(n > d) ? joint_iterator(sprout::next(current1, n - d), last1, first2, first2)
|
||||
: joint_iterator(current1, last1, first2, sprout::next(current2, n))
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR joint_iterator advance_impl(difference_type n) const {
|
||||
return n >= 0
|
||||
? is_in_left()
|
||||
? advance_impl_posite(n, NS_SSCRISK_CEL_OR_SPROUT::distance(current1, last1))
|
||||
: joint_iterator(current1, last1, first2, sprout::next(current2, n))
|
||||
: first2 == current2
|
||||
? joint_iterator(sprout::next(current1, n), last1, first2, current2)
|
||||
: advance_impl_negate(n, -NS_SSCRISK_CEL_OR_SPROUT::distance(first2, current2))
|
||||
;
|
||||
}
|
||||
public:
|
||||
joint_iterator() = default;
|
||||
joint_iterator(joint_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR joint_iterator(iterator_type it1, iterator_type last1, iterator2_type first2, iterator2_type it2)
|
||||
: current1(it1)
|
||||
, last1(last1)
|
||||
, first2(first2)
|
||||
, current2(it2)
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR joint_iterator(joint_iterator<U, V> const& it)
|
||||
: current1(it.base())
|
||||
, last1(it.left_end())
|
||||
, first2(it.right_begin())
|
||||
, current2(it.base2())
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
joint_iterator& operator=(joint_iterator<U, V> const& it) {
|
||||
joint_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current1;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type left_end() const {
|
||||
return last1;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type right_begin() const {
|
||||
return first2;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type base2() const {
|
||||
return current2;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_in_left() const {
|
||||
return current1 != last1;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return is_in_left() ? *current1 : *current2;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &*(*this);
|
||||
}
|
||||
joint_iterator& operator++() {
|
||||
if (is_in_left()) {
|
||||
++current1;
|
||||
} else {
|
||||
++current2;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
joint_iterator operator++(int) {
|
||||
joint_iterator result(*this);
|
||||
if (is_in_left()) {
|
||||
++current1;
|
||||
} else {
|
||||
++current2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
joint_iterator& operator--() {
|
||||
if (first2 == current2) {
|
||||
--current1;
|
||||
} else {
|
||||
--current2;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
joint_iterator operator--(int) {
|
||||
joint_iterator temp(*this);
|
||||
if (first2 == current2) {
|
||||
--current1;
|
||||
} else {
|
||||
--current2;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
SPROUT_CONSTEXPR joint_iterator operator+(difference_type n) const {
|
||||
return advance_impl(n);
|
||||
}
|
||||
SPROUT_CONSTEXPR joint_iterator operator-(difference_type n) const {
|
||||
return advance_impl(-n);
|
||||
}
|
||||
joint_iterator& operator+=(difference_type n) {
|
||||
joint_iterator temp(*this + n);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
joint_iterator& operator-=(difference_type n) {
|
||||
joint_iterator temp(*this - n);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
||||
return *(*this + n);
|
||||
}
|
||||
SPROUT_CONSTEXPR joint_iterator next() const {
|
||||
return is_in_left() ? joint_iterator(sprout::next(current1), last1, first2, current2)
|
||||
: joint_iterator(current1, last1, first2, sprout::next(current2))
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR joint_iterator prev() const {
|
||||
return first2 == current2 ? joint_iterator(sprout::prev(current1), last1, first2, current2)
|
||||
: joint_iterator(current1, last1, first2, sprout::prev(current2))
|
||||
;
|
||||
}
|
||||
void swap(joint_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current1, other.current1))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(last1, other.last1))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(first2, other.first2))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(current2, other.current2))
|
||||
)
|
||||
{
|
||||
sprout::swap(current1, other.current1);
|
||||
sprout::swap(last1, other.last1);
|
||||
sprout::swap(first2, other.first2);
|
||||
sprout::swap(current2, other.current2);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename LIterator1, typename RIterator1,
|
||||
typename LIterator2, typename RIterator2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::joint_iterator<LIterator1, RIterator1> const& lhs,
|
||||
sprout::joint_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base() && lhs.base2() == rhs.base2();
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1,
|
||||
typename LIterator2, typename RIterator2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator!=(
|
||||
sprout::joint_iterator<LIterator1, RIterator1> const& lhs,
|
||||
sprout::joint_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1,
|
||||
typename LIterator2, typename RIterator2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator<(
|
||||
sprout::joint_iterator<LIterator1, RIterator1> const& lhs,
|
||||
sprout::joint_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.is_in_left() && rhs.is_in_left() ? lhs.base() < rhs.base()
|
||||
: !lhs.is_in_left() && !rhs.is_in_left() ? lhs.base2() < rhs.base2()
|
||||
: lhs.is_in_left()
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1,
|
||||
typename LIterator2, typename RIterator2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator>(
|
||||
sprout::joint_iterator<LIterator1, RIterator1> const& lhs,
|
||||
sprout::joint_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1,
|
||||
typename LIterator2, typename RIterator2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator<=(
|
||||
sprout::joint_iterator<LIterator1, RIterator1> const& lhs,
|
||||
sprout::joint_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1,
|
||||
typename LIterator2, typename RIterator2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator>=(
|
||||
sprout::joint_iterator<LIterator1, RIterator1> const& lhs,
|
||||
sprout::joint_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1,
|
||||
typename LIterator2, typename RIterator2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename std::common_type<
|
||||
typename sprout::joint_iterator<LIterator1, RIterator1>::difference_type,
|
||||
typename sprout::joint_iterator<LIterator2, RIterator2>::difference_type
|
||||
>::type
|
||||
operator-(
|
||||
sprout::joint_iterator<LIterator1, RIterator1> const& lhs,
|
||||
sprout::joint_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.is_in_left() && rhs.is_in_left() ? rhs.base() - lhs.base()
|
||||
: !lhs.is_in_left() && !rhs.is_in_left() ? rhs.base2() - lhs.base2()
|
||||
: lhs.is_in_left() ? (lhs.left_end() - lhs.base()) + (rhs.base2() - rhs.right_begin())
|
||||
: (lhs.base2() - lhs.right_begin()) + (rhs.left_end() - rhs.base())
|
||||
;
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator> operator+(
|
||||
typename sprout::joint_iterator<LIterator, RIterator>::difference_type n,
|
||||
sprout::joint_iterator<LIterator, RIterator> const& it
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// make_joint_iterator
|
||||
//
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator>
|
||||
make_joint_iterator(LIterator it1, LIterator last1, RIterator first2, RIterator it2) {
|
||||
return sprout::joint_iterator<LIterator, RIterator>(it1, last1, first2, it2);
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator>
|
||||
make_joint_iterator(LIterator it1, LIterator last1, RIterator first2) {
|
||||
return sprout::joint_iterator<LIterator, RIterator>(it1, last1, first2, first2);
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator>
|
||||
make_joint_iterator(LIterator last1, RIterator first2, RIterator it2) {
|
||||
return sprout::joint_iterator<LIterator, RIterator>(last1, last1, first2, it2);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline void
|
||||
swap(
|
||||
sprout::joint_iterator<LIterator, RIterator>& lhs,
|
||||
sprout::joint_iterator<LIterator, RIterator>& rhs
|
||||
)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_distance
|
||||
//
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<sprout::joint_iterator<LIterator, RIterator> >::difference_type
|
||||
iterator_distance(
|
||||
sprout::joint_iterator<LIterator, RIterator> first,
|
||||
sprout::joint_iterator<LIterator, RIterator> last
|
||||
)
|
||||
{
|
||||
return last - first;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator>
|
||||
iterator_next(sprout::joint_iterator<LIterator, RIterator> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator>
|
||||
iterator_next(
|
||||
sprout::joint_iterator<LIterator, RIterator> const& it,
|
||||
typename sprout::joint_iterator<LIterator, RIterator>::difference_type n
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_prev
|
||||
//
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator>
|
||||
iterator_prev(sprout::joint_iterator<LIterator, RIterator> const& it) {
|
||||
return it.prev();
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::joint_iterator<LIterator, RIterator>
|
||||
iterator_prev(
|
||||
sprout::joint_iterator<LIterator, RIterator> const& it,
|
||||
typename sprout::joint_iterator<LIterator, RIterator>::difference_type n
|
||||
)
|
||||
{
|
||||
return it - n;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_JOINT_ITERATOR_HPP
|
|
@ -153,6 +153,96 @@ namespace sprout {
|
|||
typename sprout::min_iterator_category<Tail...>::type
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_category
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_category
|
||||
: public sprout::min_iterator_category<
|
||||
typename std::iterator_traits<Iterators>::iterator_category...
|
||||
>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename... Types>
|
||||
struct common_iterator_reference_impl;
|
||||
template<typename T>
|
||||
struct common_iterator_reference_impl<T> {
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T, typename U>
|
||||
struct common_iterator_reference_impl<T, U>
|
||||
: public std::conditional<
|
||||
std::is_reference<T>::value && std::is_reference<U>::value,
|
||||
typename std::conditional<
|
||||
std::is_convertible<T, U>::value
|
||||
&& (std::is_same<typename std::decay<T>::type, typename std::decay<U>::type>::value
|
||||
|| std::is_base_of<typename std::decay<U>::type, typename std::decay<T>::type>::value
|
||||
)
|
||||
,
|
||||
U,
|
||||
typename std::conditional<
|
||||
std::is_convertible<U, T>::value
|
||||
&& (std::is_same<typename std::decay<U>::type, typename std::decay<T>::type>::value
|
||||
|| std::is_base_of<typename std::decay<T>::type, typename std::decay<U>::type>::value
|
||||
)
|
||||
,
|
||||
T,
|
||||
typename std::common_type<typename std::decay<T>::type, typename std::decay<U>::type>::type
|
||||
>::type
|
||||
>::type,
|
||||
typename std::common_type<typename std::decay<T>::type, typename std::decay<U>::type>::type
|
||||
>
|
||||
{};
|
||||
template<typename T, typename U, typename... Tail>
|
||||
struct common_iterator_reference_impl<T, U, Tail...>
|
||||
: public sprout::detail::common_iterator_reference_impl<
|
||||
typename sprout::detail::common_iterator_reference_impl<T, U>::type,
|
||||
Tail...
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// common_iterator_reference
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_reference
|
||||
: public sprout::detail::common_iterator_reference_impl<
|
||||
typename std::iterator_traits<Iterators>::reference...
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_value_type
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_value_type
|
||||
: public std::decay<
|
||||
typename sprout::common_iterator_reference<Iterators...>::type
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_pointer
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_pointer
|
||||
: public std::add_pointer<
|
||||
typename std::remove_reference<typename sprout::common_iterator_reference<Iterators...>::type>::type
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_difference_type
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_difference_type
|
||||
: public std::common_type<
|
||||
typename std::iterator_traits<Iterators>::difference_type...
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_TRAITS_HPP
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/iterator/traits.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -18,10 +18,7 @@ namespace sprout {
|
|||
template<typename BinaryFunction, typename LIterator, typename RIterator = void>
|
||||
class transform_iterator
|
||||
: public std::iterator<
|
||||
typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<LIterator>::iterator_category,
|
||||
typename std::iterator_traits<RIterator>::iterator_category
|
||||
>::type,
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
typename std::remove_reference<
|
||||
typename std::result_of<
|
||||
BinaryFunction (
|
||||
|
@ -51,10 +48,7 @@ namespace sprout {
|
|||
typedef BinaryFunction functor_type;
|
||||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename std::iterator_traits<LIterator>::iterator_category,
|
||||
typename std::iterator_traits<RIterator>::iterator_category
|
||||
>::type iterator_category;
|
||||
typedef typename sprout::common_iterator_category<LIterator, RIterator>::type iterator_category;
|
||||
typedef typename std::result_of<
|
||||
BinaryFunction (
|
||||
typename std::iterator_traits<LIterator>::reference,
|
||||
|
|
8
sprout/iterator/type_traits.hpp
Normal file
8
sprout/iterator/type_traits.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_ITERATOR_TYPE_TRAITS_HPP
|
||||
#define SPROUT_ITERATOR_TYPE_TRAITS_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_TYPE_TRAITS_HPP
|
164
sprout/iterator/type_traits/common.hpp
Normal file
164
sprout/iterator/type_traits/common.hpp
Normal file
|
@ -0,0 +1,164 @@
|
|||
#ifndef SPROUT_ITERATOR_TYPE_TRAITS_COMMON_HPP
|
||||
#define SPROUT_ITERATOR_TYPE_TRAITS_COMMON_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/type_traits/is_iterator.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename Category, bool IsRandomAccess, bool IsBidirectional, bool IsForward, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl;
|
||||
template<typename Category, bool IsBidirectional, bool IsForward, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl<Category, true, IsBidirectional, IsForward, IsSinglePassOrIncrementable>
|
||||
: public std::integral_constant<int, 4>
|
||||
{};
|
||||
template<typename Category, bool IsForward, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl<Category, false, true, IsForward, IsSinglePassOrIncrementable>
|
||||
: public std::integral_constant<int, 3>
|
||||
{};
|
||||
template<typename Category, bool IsSinglePassOrIncrementable>
|
||||
struct iterator_category_hierarchy_impl<Category, false, false, true, IsSinglePassOrIncrementable>
|
||||
: public std::integral_constant<int, 2>
|
||||
{};
|
||||
template<typename Category>
|
||||
struct iterator_category_hierarchy_impl<Category, false, false, false, true>
|
||||
: public std::integral_constant<int, 1>
|
||||
{};
|
||||
|
||||
template<typename Category>
|
||||
struct iterator_category_hierarchy
|
||||
: public sprout::detail::iterator_category_hierarchy_impl<
|
||||
Category,
|
||||
sprout::is_random_access_iterator_category<Category>::value,
|
||||
sprout::is_bidirectional_iterator_category<Category>::value,
|
||||
sprout::is_forward_iterator_category<Category>::value,
|
||||
sprout::is_input_iterator_category<Category>::value || sprout::is_output_iterator_category<Category>::value
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Category1, typename Category2>
|
||||
struct iterator_category_less
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
(sprout::detail::iterator_category_hierarchy<Category1>::value < sprout::detail::iterator_category_hierarchy<Category2>::value)
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// min_iterator_category
|
||||
//
|
||||
template<typename Head, typename... Tail>
|
||||
struct min_iterator_category;
|
||||
template<typename Category>
|
||||
struct min_iterator_category<Category>
|
||||
: public std::common_type<Category>
|
||||
{};
|
||||
template<typename Category1, typename Category2>
|
||||
struct min_iterator_category<Category1, Category2>
|
||||
: public std::conditional<
|
||||
sprout::detail::iterator_category_less<Category1, Category2>::value,
|
||||
Category1, Category2
|
||||
>
|
||||
{};
|
||||
template<typename Head, typename... Tail>
|
||||
struct min_iterator_category
|
||||
: public sprout::min_iterator_category<
|
||||
Head,
|
||||
typename sprout::min_iterator_category<Tail...>::type
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_category
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_category
|
||||
: public sprout::min_iterator_category<
|
||||
typename std::iterator_traits<Iterators>::iterator_category...
|
||||
>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename... Types>
|
||||
struct common_iterator_reference_impl;
|
||||
template<typename T>
|
||||
struct common_iterator_reference_impl<T> {
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T, typename U>
|
||||
struct common_iterator_reference_impl<T, U>
|
||||
: public std::conditional<
|
||||
std::is_reference<T>::value && std::is_reference<U>::value,
|
||||
typename std::conditional<
|
||||
std::is_convertible<T, U>::value
|
||||
&& (std::is_same<typename std::decay<T>::type, typename std::decay<U>::type>::value
|
||||
|| std::is_base_of<typename std::decay<U>::type, typename std::decay<T>::type>::value
|
||||
)
|
||||
,
|
||||
U,
|
||||
typename std::conditional<
|
||||
std::is_convertible<U, T>::value
|
||||
&& (std::is_same<typename std::decay<U>::type, typename std::decay<T>::type>::value
|
||||
|| std::is_base_of<typename std::decay<T>::type, typename std::decay<U>::type>::value
|
||||
)
|
||||
,
|
||||
T,
|
||||
typename std::common_type<typename std::decay<T>::type, typename std::decay<U>::type>::type
|
||||
>::type
|
||||
>::type,
|
||||
typename std::common_type<typename std::decay<T>::type, typename std::decay<U>::type>::type
|
||||
>
|
||||
{};
|
||||
template<typename T, typename U, typename... Tail>
|
||||
struct common_iterator_reference_impl<T, U, Tail...>
|
||||
: public sprout::detail::common_iterator_reference_impl<
|
||||
typename sprout::detail::common_iterator_reference_impl<T, U>::type,
|
||||
Tail...
|
||||
>
|
||||
{};
|
||||
} // namespace detail
|
||||
//
|
||||
// common_iterator_reference
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_reference
|
||||
: public sprout::detail::common_iterator_reference_impl<
|
||||
typename std::iterator_traits<Iterators>::reference...
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_value_type
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_value_type
|
||||
: public std::decay<
|
||||
typename sprout::common_iterator_reference<Iterators...>::type
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_pointer
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_pointer
|
||||
: public std::add_pointer<
|
||||
typename std::remove_reference<typename sprout::common_iterator_reference<Iterators...>::type>::type
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// common_iterator_difference_type
|
||||
//
|
||||
template<typename... Iterators>
|
||||
struct common_iterator_difference_type
|
||||
: public std::common_type<
|
||||
typename std::iterator_traits<Iterators>::difference_type...
|
||||
>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_TYPE_TRAITS_COMMON_HPP
|
97
sprout/iterator/type_traits/is_iterator.hpp
Normal file
97
sprout/iterator/type_traits/is_iterator.hpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#ifndef SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
//
|
||||
// has_iterator_category
|
||||
//
|
||||
SPROUT_HAS_XXX_TYPE_DEF_LAZY(iterator_category);
|
||||
} // namespace detail
|
||||
//
|
||||
// is_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_iterator
|
||||
: public sprout::detail::has_iterator_category<std::iterator_traits<Iterator> >
|
||||
{};
|
||||
|
||||
//
|
||||
// is_input_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_input_iterator_category
|
||||
: public std::is_convertible<Category, std::input_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_output_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_output_iterator_category
|
||||
: public std::is_convertible<Category, std::output_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_forward_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_forward_iterator_category
|
||||
: public std::is_convertible<Category, std::forward_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_bidirectional_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_bidirectional_iterator_category
|
||||
: public std::is_convertible<Category, std::bidirectional_iterator_tag>
|
||||
{};
|
||||
//
|
||||
// is_random_access_iterator_category
|
||||
//
|
||||
template<typename Category>
|
||||
struct is_random_access_iterator_category
|
||||
: public std::is_convertible<Category, std::random_access_iterator_tag>
|
||||
{};
|
||||
|
||||
//
|
||||
// is_input_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_input_iterator
|
||||
: public sprout::is_input_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
//
|
||||
// is_output_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_output_iterator
|
||||
: public sprout::is_output_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
//
|
||||
// is_forward_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_forward_iterator
|
||||
: public sprout::is_forward_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
//
|
||||
// is_bidirectional_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_bidirectional_iterator
|
||||
: public sprout::is_bidirectional_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
//
|
||||
// is_random_access_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
struct is_random_access_iterator
|
||||
: public sprout::is_random_access_iterator_category<typename std::iterator_traits<Iterator>::iterator_category>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP
|
|
@ -2,23 +2,8 @@
|
|||
#define SPROUT_RANDOM_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/linear_congruential.hpp>
|
||||
#include <sprout/random/inversive_congruential.hpp>
|
||||
#include <sprout/random/mersenne_twister.hpp>
|
||||
#include <sprout/random/linear_feedback_shift.hpp>
|
||||
#include <sprout/random/shuffle_order.hpp>
|
||||
#include <sprout/random/additive_combine.hpp>
|
||||
#include <sprout/random/xor_combine.hpp>
|
||||
#include <sprout/random/taus88.hpp>
|
||||
#include <sprout/random/default_random_engine.hpp>
|
||||
#include <sprout/random/uniform_smallint.hpp>
|
||||
#include <sprout/random/uniform_int_distribution.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
#include <sprout/random/uniform_real_distribution.hpp>
|
||||
#include <sprout/random/bernoulli_distribution.hpp>
|
||||
#include <sprout/random/binomial_distribution.hpp>
|
||||
#include <sprout/random/geometric_distribution.hpp>
|
||||
#include <sprout/random/normal_distribution.hpp>
|
||||
#include <sprout/random/engine.hpp>
|
||||
#include <sprout/random/distribution.hpp>
|
||||
#include <sprout/random/variate_generator.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/iterator.hpp>
|
||||
|
|
14
sprout/random/distribution.hpp
Normal file
14
sprout/random/distribution.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef SPROUT_RANDOM_DISTRIBUTION_HPP
|
||||
#define SPROUT_RANDOM_DISTRIBUTION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/uniform_smallint.hpp>
|
||||
#include <sprout/random/uniform_int_distribution.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
#include <sprout/random/uniform_real_distribution.hpp>
|
||||
#include <sprout/random/bernoulli_distribution.hpp>
|
||||
#include <sprout/random/binomial_distribution.hpp>
|
||||
#include <sprout/random/geometric_distribution.hpp>
|
||||
#include <sprout/random/normal_distribution.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_DISTRIBUTION_HPP
|
15
sprout/random/engine.hpp
Normal file
15
sprout/random/engine.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef SPROUT_RANDOM_ENGINE_HPP
|
||||
#define SPROUT_RANDOM_ENGINE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/random/linear_congruential.hpp>
|
||||
#include <sprout/random/inversive_congruential.hpp>
|
||||
#include <sprout/random/mersenne_twister.hpp>
|
||||
#include <sprout/random/linear_feedback_shift.hpp>
|
||||
#include <sprout/random/shuffle_order.hpp>
|
||||
#include <sprout/random/additive_combine.hpp>
|
||||
#include <sprout/random/xor_combine.hpp>
|
||||
#include <sprout/random/taus88.hpp>
|
||||
#include <sprout/random/default_random_engine.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_RANDOM_ENGINE_HPP
|
|
@ -12,6 +12,7 @@
|
|||
#include <sprout/range/adaptor/outdirected.hpp>
|
||||
#include <sprout/range/adaptor/indexed.hpp>
|
||||
#include <sprout/range/adaptor/valued.hpp>
|
||||
#include <sprout/range/adaptor/jointed.hpp>
|
||||
#include <sprout/range/adaptor/deep_copied.hpp>
|
||||
#include <sprout/range/adaptor/sized.hpp>
|
||||
#include <sprout/range/adaptor/size_enumed.hpp>
|
||||
|
|
146
sprout/range/adaptor/jointed.hpp
Normal file
146
sprout/range/adaptor/jointed.hpp
Normal file
|
@ -0,0 +1,146 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_JOINTED_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_JOINTED_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/joint_iterator.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include <sprout/utility/value_holder.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
//
|
||||
// jointed_range
|
||||
//
|
||||
template<typename LRange, typename RRange>
|
||||
class jointed_range
|
||||
: public sprout::range::range_container<
|
||||
sprout::joint_iterator<
|
||||
typename sprout::container_traits<LRange>::iterator,
|
||||
typename sprout::container_traits<RRange>::iterator
|
||||
>
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<LRange>
|
||||
, public sprout::detail::container_nosy_fixed_size<LRange>
|
||||
{
|
||||
public:
|
||||
typedef LRange range_type;
|
||||
typedef RRange range2_type;
|
||||
typedef sprout::range::range_container<
|
||||
sprout::joint_iterator<
|
||||
typename sprout::container_traits<LRange>::iterator,
|
||||
typename sprout::container_traits<RRange>::iterator
|
||||
>
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
jointed_range() = default;
|
||||
jointed_range(jointed_range const&) = default;
|
||||
SPROUT_CONSTEXPR jointed_range(range_type& range1, range2_type& range2)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::begin(range2)),
|
||||
iterator(sprout::end(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2))
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// joint_holder
|
||||
//
|
||||
template<typename RRange>
|
||||
class joint_holder {
|
||||
public:
|
||||
typedef RRange range2_type;
|
||||
private:
|
||||
sprout::value_holder<range2_type&> range_;
|
||||
public:
|
||||
joint_holder() = default;
|
||||
joint_holder(joint_holder const&) = default;
|
||||
explicit SPROUT_CONSTEXPR joint_holder(range2_type& range)
|
||||
: range_(range)
|
||||
{}
|
||||
SPROUT_CONSTEXPR range2_type& range() const {
|
||||
return range_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// jointed_forwarder
|
||||
//
|
||||
class jointed_forwarder {
|
||||
public:
|
||||
template<typename RRange>
|
||||
SPROUT_CONSTEXPR sprout::adaptors::joint_holder<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
|
||||
>
|
||||
operator()(RRange&& range) {
|
||||
return sprout::adaptors::joint_holder<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<RRange>(range)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// jointed
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::jointed_forwarder jointed{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename LRange, typename RRange>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::jointed_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<LRange>::type>::type,
|
||||
RRange
|
||||
>
|
||||
operator|(LRange&& lhs, sprout::adaptors::joint_holder<RRange> const& rhs) {
|
||||
return sprout::adaptors::jointed_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<LRange>::type>::type,
|
||||
RRange
|
||||
>(
|
||||
sprout::lvalue_forward<LRange>(lhs),
|
||||
rhs.range()
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename LRange, typename RRange>
|
||||
struct container_construct_traits<sprout::adaptors::jointed_range<LRange, RRange> > {
|
||||
public:
|
||||
typedef typename sprout::container_construct_traits<LRange>::copied_type copied_type;
|
||||
public:
|
||||
template<typename Cont>
|
||||
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
|
||||
return sprout::range::fixed::copy(sprout::forward<Cont>(cont), sprout::pit<copied_type>());
|
||||
}
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
|
||||
return sprout::make<copied_type>(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename Cont, typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type remake(
|
||||
Cont&& cont,
|
||||
typename sprout::container_traits<sprout::adaptors::jointed_range<LRange, RRange> >::difference_type size,
|
||||
Args&&... args
|
||||
)
|
||||
{
|
||||
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_JOINTED_HPP
|
Loading…
Reference in a new issue