mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add adaptors::blanked
This commit is contained in:
parent
e286c9bc6b
commit
ded2da84ea
27 changed files with 350 additions and 349 deletions
|
@ -10,10 +10,11 @@
|
|||
#include <sprout/range/adaptor/filtered.hpp>
|
||||
#include <sprout/range/adaptor/counting.hpp>
|
||||
#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/indexed.hpp>
|
||||
#include <sprout/range/adaptor/valued.hpp>
|
||||
#include <sprout/range/adaptor/blanked.hpp>
|
||||
#include <sprout/range/adaptor/sized.hpp>
|
||||
#include <sprout/range/adaptor/size_enumed.hpp>
|
||||
#include <sprout/range/adaptor/wave.hpp>
|
||||
|
|
189
sprout/range/adaptor/blanked.hpp
Normal file
189
sprout/range/adaptor/blanked.hpp
Normal file
|
@ -0,0 +1,189 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_BLANKED_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_BLANKED_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/value_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 HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// blank_t
|
||||
//
|
||||
struct blank_t {};
|
||||
|
||||
namespace adaptors {
|
||||
//
|
||||
// blanked_range
|
||||
//
|
||||
template<typename T = sprout::blank_t, typename Range = void>
|
||||
class blanked_range
|
||||
: public sprout::range::range_container<
|
||||
sprout::value_iterator<T>
|
||||
>
|
||||
, 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::value_iterator<T>
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::value_type value_type;
|
||||
typedef typename base_type::difference_type difference_type;
|
||||
typedef typename base_type::size_type size_type;
|
||||
public:
|
||||
blanked_range() = default;
|
||||
blanked_range(blanked_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR blanked_range(range_type& range)
|
||||
: base_type(
|
||||
iterator(value_type(), sprout::size(range)),
|
||||
iterator(value_type(), 0)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR blanked_range(
|
||||
range_type& range,
|
||||
difference_type n
|
||||
)
|
||||
: base_type(
|
||||
iterator(value_type(), static_cast<difference_type>(NS_SSCRISK_CEL_OR_SPROUT::min<size_type>(n, sprout::size(range)))),
|
||||
iterator(value_type(), 0)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR blanked_range(
|
||||
range_type& range,
|
||||
difference_type n,
|
||||
value_type const& value
|
||||
)
|
||||
: base_type(
|
||||
iterator(value, static_cast<difference_type>(NS_SSCRISK_CEL_OR_SPROUT::min<size_type>(n, sprout::size(range)))),
|
||||
iterator(value, 0)
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class blanked_range<T, void>
|
||||
: public sprout::range::range_container<
|
||||
sprout::value_iterator<T>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef sprout::range::range_container<
|
||||
sprout::value_iterator<T>
|
||||
> base_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::value_type value_type;
|
||||
typedef typename base_type::difference_type difference_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR blanked_range()
|
||||
: base_type(
|
||||
iterator(value_type()),
|
||||
iterator(value_type(), 0)
|
||||
)
|
||||
{}
|
||||
blanked_range(blanked_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR blanked_range(difference_type n)
|
||||
: base_type(
|
||||
iterator(value_type(), n),
|
||||
iterator(value_type(), 0)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR blanked_range(
|
||||
difference_type n,
|
||||
value_type const& value
|
||||
)
|
||||
: base_type(
|
||||
iterator(value, n),
|
||||
iterator(value, 0)
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// blanked_forwarder
|
||||
//
|
||||
class blanked_forwarder {
|
||||
public:
|
||||
SPROUT_CONSTEXPR sprout::adaptors::blanked_range<>
|
||||
operator()() const {
|
||||
return sprout::adaptors::blanked_range<>();
|
||||
}
|
||||
template<typename Difference>
|
||||
SPROUT_CONSTEXPR sprout::adaptors::blanked_range<>
|
||||
operator()(Difference n) const {
|
||||
return sprout::adaptors::blanked_range<>(n);
|
||||
}
|
||||
template<typename T, typename Difference>
|
||||
SPROUT_CONSTEXPR sprout::adaptors::blanked_range<T>
|
||||
operator()(Difference n, T const& value) const {
|
||||
return sprout::adaptors::blanked_range<T>(n, value);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// blanked
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::blanked_forwarder blanked{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::blanked_range<
|
||||
T,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::blanked_range<T> const& rhs) {
|
||||
return sprout::adaptors::blanked_range<
|
||||
T,
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs),
|
||||
sprout::size(rhs),
|
||||
!sprout::empty(rhs) ? *rhs.begin()
|
||||
: typename sprout::container_traits<sprout::adaptors::blanked_range<T> >::value_type()
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename T, typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::blanked_range<T, 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::blanked_range<T, 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_BLANKED_HPP
|
|
@ -48,13 +48,13 @@ namespace sprout {
|
|||
iterator(sprout::size(range), frequency, amplitude, phase)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& frequency() const {
|
||||
SPROUT_CONSTEXPR value_type frequency() const {
|
||||
return base_type::begin().frequency();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
||||
SPROUT_CONSTEXPR value_type amplitude() const {
|
||||
return base_type::begin().amplitude();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& phase() const {
|
||||
SPROUT_CONSTEXPR value_type phase() const {
|
||||
return base_type::begin().phase();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -48,13 +48,13 @@ namespace sprout {
|
|||
iterator(sprout::size(range), frequency, amplitude, phase)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& frequency() const {
|
||||
SPROUT_CONSTEXPR value_type frequency() const {
|
||||
return base_type::begin().frequency();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
||||
SPROUT_CONSTEXPR value_type amplitude() const {
|
||||
return base_type::begin().amplitude();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& phase() const {
|
||||
SPROUT_CONSTEXPR value_type phase() const {
|
||||
return base_type::begin().phase();
|
||||
}
|
||||
};
|
||||
|
@ -85,13 +85,13 @@ namespace sprout {
|
|||
iterator(-1, frequency, amplitude, phase)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& frequency() const {
|
||||
SPROUT_CONSTEXPR value_type frequency() const {
|
||||
return base_type::begin().frequency();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
||||
SPROUT_CONSTEXPR value_type amplitude() const {
|
||||
return base_type::begin().amplitude();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& phase() const {
|
||||
SPROUT_CONSTEXPR value_type phase() const {
|
||||
return base_type::begin().phase();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -49,16 +49,16 @@ namespace sprout {
|
|||
iterator(sprout::size(range), frequency, amplitude, phase, duty)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& frequency() const {
|
||||
SPROUT_CONSTEXPR value_type frequency() const {
|
||||
return base_type::begin().frequency();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
||||
SPROUT_CONSTEXPR value_type amplitude() const {
|
||||
return base_type::begin().amplitude();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& phase() const {
|
||||
SPROUT_CONSTEXPR value_type phase() const {
|
||||
return base_type::begin().phase();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& duty() const {
|
||||
SPROUT_CONSTEXPR value_type duty() const {
|
||||
return base_type::begin().duty();
|
||||
}
|
||||
};
|
||||
|
@ -90,16 +90,16 @@ namespace sprout {
|
|||
iterator(-1, frequency, amplitude, phase, duty)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& frequency() const {
|
||||
SPROUT_CONSTEXPR value_type frequency() const {
|
||||
return base_type::begin().frequency();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
||||
SPROUT_CONSTEXPR value_type amplitude() const {
|
||||
return base_type::begin().amplitude();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& phase() const {
|
||||
SPROUT_CONSTEXPR value_type phase() const {
|
||||
return base_type::begin().phase();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& duty() const {
|
||||
SPROUT_CONSTEXPR value_type duty() const {
|
||||
return base_type::begin().duty();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -48,13 +48,13 @@ namespace sprout {
|
|||
iterator(sprout::size(range), frequency, amplitude, phase)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& frequency() const {
|
||||
SPROUT_CONSTEXPR value_type frequency() const {
|
||||
return base_type::begin().frequency();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
||||
SPROUT_CONSTEXPR value_type amplitude() const {
|
||||
return base_type::begin().amplitude();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& phase() const {
|
||||
SPROUT_CONSTEXPR value_type phase() const {
|
||||
return base_type::begin().phase();
|
||||
}
|
||||
};
|
||||
|
@ -85,13 +85,13 @@ namespace sprout {
|
|||
iterator(-1, frequency, amplitude, phase)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& frequency() const {
|
||||
SPROUT_CONSTEXPR value_type frequency() const {
|
||||
return base_type::begin().frequency();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
||||
SPROUT_CONSTEXPR value_type amplitude() const {
|
||||
return base_type::begin().amplitude();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& phase() const {
|
||||
SPROUT_CONSTEXPR value_type phase() const {
|
||||
return base_type::begin().phase();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue