mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix adaptors alternated, taken, dropped, etc...
This commit is contained in:
parent
84e3348402
commit
86818d73cb
16 changed files with 207 additions and 157 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
#include <sprout/operation/fixed/set.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
namespace brainfuck {
|
||||
|
@ -68,7 +69,12 @@ namespace sprout {
|
|||
{
|
||||
typedef typename std::iterator_traits<SourceBidirectionalIterator>::value_type value_type;
|
||||
typedef typename sprout::container_traits<OutputBuffer>::value_type out_value_type;
|
||||
return first == last ? sprout::fixed::copy(out_buffer.begin(), out_buffer.end(), output)
|
||||
return first == last
|
||||
? sprout::fixed::copy(
|
||||
sprout::begin(out_buffer),
|
||||
sprout::next(sprout::begin(out_buffer), NS_SSCRISK_CEL_OR_SPROUT::min(out_pos, sprout::size(out_buffer))),
|
||||
output
|
||||
)
|
||||
: *first == value_type('>')
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(first), last, output, in_first, in_last,
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/type_traits/arithmetic_promote.hpp>
|
||||
#include <sprout/utility/limited.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
|
@ -242,7 +242,10 @@ namespace sprout {
|
|||
sprout::alternate_iterator<LIterator2, RIterator2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() - rhs.base() + (lhs.is_in_left() ? (rhs.is_in_left() ? 0 : 1) : (rhs.is_in_left() ? 1 : 0));
|
||||
return sprout::limited::plus(
|
||||
sprout::limited::multiplies(lhs.base() - rhs.base(), 2),
|
||||
lhs.is_in_left() ? (rhs.is_in_left() ? 0 : 1) : (rhs.is_in_left() ? 1 : 0)
|
||||
);
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::alternate_iterator<LIterator, RIterator> operator+(
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
@ -21,17 +21,11 @@ namespace sprout {
|
|||
//
|
||||
template<typename Range>
|
||||
class copied_range
|
||||
: public sprout::range::range_container<
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
: public sprout::adaptors::detail::adapted_range_default<Range>
|
||||
{
|
||||
public:
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
> base_type;
|
||||
typedef sprout::adaptors::detail::adapted_range_default<Range> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
public:
|
||||
copied_range() = default;
|
||||
copied_range(copied_range const&) = default;
|
||||
|
@ -111,28 +105,9 @@ namespace sprout {
|
|||
// container_construct_traits
|
||||
//
|
||||
template<typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::copied_range<Range> > {
|
||||
public:
|
||||
typedef typename sprout::container_construct_traits<Range>::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::copied_range<Range> >::difference_type size,
|
||||
Args&&... args
|
||||
)
|
||||
{
|
||||
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
struct container_construct_traits<sprout::adaptors::copied_range<Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::copied_range<Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_COPIED_HPP
|
||||
|
|
63
sprout/range/adaptor/detail/adapted_range_default.hpp
Normal file
63
sprout/range/adaptor/detail/adapted_range_default.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_DETAIL_ADAPTED_RANGE_DEFAULT_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_DETAIL_ADAPTED_RANGE_DEFAULT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
namespace detail {
|
||||
template<typename Range, typename Iterator = typename sprout::container_traits<Range>::iterator>
|
||||
class adapted_range_default
|
||||
: public sprout::range::range_container<Iterator>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
{
|
||||
public:
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<Iterator> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
adapted_range_default() = default;
|
||||
adapted_range_default(adapted_range_default const&) = default;
|
||||
explicit SPROUT_CONSTEXPR adapted_range_default(iterator const& first, iterator const& last)
|
||||
: base_type(first, last)
|
||||
{}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Range, typename Iterator>
|
||||
struct container_construct_traits<sprout::adaptors::detail::adapted_range_default<Range, Iterator> > {
|
||||
public:
|
||||
typedef typename sprout::container_construct_traits<Range>::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::detail::adapted_range_default<Range> >::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_DETAIL_ADAPTED_RANGE_DEFAULT_HPP
|
|
@ -6,7 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
@ -54,15 +54,15 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Difference>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::drop_holder<Difference> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::next(
|
||||
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
@ -54,15 +54,15 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Difference>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::drop_end_holder<Difference> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
||||
sprout::next(
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/type_traits/arithmetic_promote.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
|
@ -78,15 +78,15 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Difference1, typename Difference2>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::offset_holder<Difference1, Difference2> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::next(
|
||||
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
||||
|
@ -102,15 +102,15 @@ namespace sprout {
|
|||
);
|
||||
}
|
||||
template<typename Range, typename Difference>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::offset_holder<Difference> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::next(
|
||||
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/reverse_iterator.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
@ -20,21 +20,17 @@ namespace sprout {
|
|||
//
|
||||
template<typename Range>
|
||||
class reversed_range
|
||||
: public sprout::range::range_container<
|
||||
sprout::reverse_iterator<
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::reverse_iterator<typename sprout::container_traits<Range>::iterator>
|
||||
>
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
{
|
||||
public:
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<
|
||||
sprout::reverse_iterator<
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::reverse_iterator<typename sprout::container_traits<Range>::iterator>
|
||||
> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
reversed_range() = default;
|
||||
|
@ -79,28 +75,9 @@ namespace sprout {
|
|||
// container_construct_traits
|
||||
//
|
||||
template<typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::reversed_range<Range> > {
|
||||
public:
|
||||
typedef typename sprout::container_construct_traits<Range>::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::reversed_range<Range> >::difference_type size,
|
||||
Args&&... args
|
||||
)
|
||||
{
|
||||
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
struct container_construct_traits<sprout::adaptors::reversed_range<Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::reversed_range<Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_REVERSED_HPP
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
@ -54,15 +54,15 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Difference>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::take_holder<Difference> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
||||
sprout::next(
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
@ -54,15 +54,15 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Difference>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::take_end_holder<Difference> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::next(
|
||||
sprout::end(sprout::lvalue_forward<Range>(lhs)),
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
@ -21,21 +21,21 @@ namespace sprout {
|
|||
//
|
||||
template<typename BinaryFunction, typename LRange, typename RRange = void>
|
||||
class transformed_range
|
||||
: public sprout::range::range_container<
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
LRange,
|
||||
sprout::transform_iterator<
|
||||
BinaryFunction,
|
||||
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 BinaryFunction functor_type;
|
||||
typedef LRange range_type;
|
||||
typedef LRange range1_type;
|
||||
typedef RRange range2_type;
|
||||
typedef sprout::range::range_container<
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
LRange,
|
||||
sprout::transform_iterator<
|
||||
BinaryFunction,
|
||||
typename sprout::container_traits<LRange>::iterator,
|
||||
|
@ -43,11 +43,10 @@ namespace sprout {
|
|||
>
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::size_type size_type;
|
||||
public:
|
||||
transformed_range() = default;
|
||||
transformed_range(transformed_range const&) = default;
|
||||
SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range1, range2_type& range2)
|
||||
SPROUT_CONSTEXPR transformed_range(functor_type func, range1_type& range1, range2_type& range2)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range1), sprout::begin(range2), func),
|
||||
iterator(sprout::end(range1), sprout::end(range2), func)
|
||||
|
@ -57,19 +56,19 @@ namespace sprout {
|
|||
|
||||
template<typename UnaryFunction, typename Range>
|
||||
class transformed_range<UnaryFunction, Range, void>
|
||||
: public sprout::range::range_container<
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::transform_iterator<
|
||||
UnaryFunction,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
>
|
||||
, public sprout::detail::container_nosy_static_size<Range>
|
||||
, public sprout::detail::container_nosy_fixed_size<Range>
|
||||
{
|
||||
public:
|
||||
typedef UnaryFunction functor_type;
|
||||
typedef Range range_type;
|
||||
typedef sprout::range::range_container<
|
||||
typedef Range range1_type;
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::transform_iterator<
|
||||
UnaryFunction,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
|
@ -79,7 +78,7 @@ namespace sprout {
|
|||
public:
|
||||
transformed_range() = default;
|
||||
transformed_range(transformed_range const&) = default;
|
||||
SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range)
|
||||
SPROUT_CONSTEXPR transformed_range(functor_type func, range1_type& range)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), func),
|
||||
iterator(sprout::end(range), func)
|
||||
|
@ -202,28 +201,9 @@ namespace sprout {
|
|||
// container_construct_traits
|
||||
//
|
||||
template<typename UnaryOrBinaryFunction, typename LRange, typename RRange>
|
||||
struct container_construct_traits<sprout::adaptors::transformed_range<UnaryOrBinaryFunction, 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::transformed_range<UnaryOrBinaryFunction, LRange, RRange> >::difference_type size,
|
||||
Args&&... args
|
||||
)
|
||||
{
|
||||
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
struct container_construct_traits<sprout::adaptors::transformed_range<UnaryOrBinaryFunction, LRange, RRange> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::transformed_range<UnaryOrBinaryFunction, LRange, RRange>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_TRANSFORMD_HPP
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/range/range_container.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/type_traits/arithmetic_promote.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
|
@ -78,15 +78,15 @@ namespace sprout {
|
|||
// operator|
|
||||
//
|
||||
template<typename Range, typename Difference1, typename Difference2>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::window_holder<Difference1, Difference2> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::next(
|
||||
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
||||
|
@ -99,15 +99,15 @@ namespace sprout {
|
|||
);
|
||||
}
|
||||
template<typename Range, typename Difference>
|
||||
inline SPROUT_CONSTEXPR sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::window_holder<Difference> const& rhs) {
|
||||
typedef typename sprout::container_traits<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>::difference_type difference_type;
|
||||
return sprout::range::range_container<
|
||||
typename sprout::container_traits<typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type>::iterator
|
||||
return sprout::adaptors::detail::adapted_range_default<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::next(
|
||||
sprout::begin(sprout::lvalue_forward<Range>(lhs)),
|
||||
|
|
46
sprout/utility/limited.hpp
Normal file
46
sprout/utility/limited.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef SPROUT_INTEGER_LIMITED_HPP
|
||||
#define SPROUT_INTEGER_LIMITED_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/arithmetic_promote.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace limited {
|
||||
//
|
||||
// plus
|
||||
//
|
||||
template<typename T, typename U>
|
||||
inline SPROUT_CONSTEXPR typename sprout::arithmetic_promote<T, U>::type
|
||||
plus(T const& lhs, U const& rhs) {
|
||||
typedef typename sprout::arithmetic_promote<T, U>::type type;
|
||||
return lhs > 0 && rhs > 0 && std::numeric_limits<type>::max() - lhs < rhs
|
||||
? std::numeric_limits<type>::max()
|
||||
: lhs < 0 && rhs < 0 && std::numeric_limits<type>::min() - lhs > rhs
|
||||
? std::numeric_limits<type>::min()
|
||||
: lhs + rhs
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// multiplies
|
||||
//
|
||||
template<typename T, typename U>
|
||||
inline SPROUT_CONSTEXPR typename sprout::arithmetic_promote<T, U>::type
|
||||
multiplies(T const& lhs, U const& rhs) {
|
||||
typedef typename sprout::arithmetic_promote<T, U>::type type;
|
||||
return lhs > 0 && rhs > 0 && std::numeric_limits<type>::max() / lhs + (std::numeric_limits<type>::max() % lhs ? 1 : 0) <= rhs
|
||||
? std::numeric_limits<type>::max()
|
||||
: lhs > 0 && rhs < 0 && std::numeric_limits<type>::min() / rhs + (std::numeric_limits<type>::min() % rhs ? 1 : 0) <= lhs
|
||||
? std::numeric_limits<type>::min()
|
||||
: lhs < 0 && rhs > 0 && std::numeric_limits<type>::min() / lhs + (std::numeric_limits<type>::min() % lhs ? 1 : 0) <= rhs
|
||||
? std::numeric_limits<type>::min()
|
||||
: lhs < 0 && rhs < 0 && -(std::numeric_limits<type>::min() / rhs + (std::numeric_limits<type>::min() % rhs ? 1 : 0)) >= lhs
|
||||
? std::numeric_limits<type>::max()
|
||||
: lhs * rhs
|
||||
;
|
||||
}
|
||||
} // namespace limited
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_INTEGER_LIMITED_HPP
|
|
@ -6,5 +6,6 @@
|
|||
#include <sprout/utility/as_lvalue.hpp>
|
||||
#include <sprout/utility/as_const.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include <sprout/utility/limited.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_OPERATION_EXT_HPP
|
||||
|
|
|
@ -45,7 +45,6 @@ namespace sprout {
|
|||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return res.success()
|
||||
? result_type(true, res.current(), value_)
|
||||
: result_type(false, first, value_)
|
||||
|
|
|
@ -18,18 +18,6 @@ namespace sprout {
|
|||
template<typename T, typename = void>
|
||||
struct is_parser;
|
||||
template<typename T>
|
||||
struct is_parser<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
std::is_const<T>::value
|
||||
&& !std::is_array<T>::value
|
||||
>::type
|
||||
>
|
||||
: public sprout::weed::traits::is_parser<
|
||||
typename std::remove_const<T>::type
|
||||
>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_parser<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
|
@ -68,6 +56,18 @@ namespace sprout {
|
|||
>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_parser<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
std::is_const<T>::value
|
||||
&& !std::is_array<T>::value
|
||||
>::type
|
||||
>
|
||||
: public sprout::weed::traits::is_parser<
|
||||
typename std::remove_const<T>::type
|
||||
>
|
||||
{};
|
||||
} // namespace traits
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
|
Loading…
Reference in a new issue