2012-11-17 12:47:52 +00:00
|
|
|
#ifndef SPROUT_COMPOST_EFFECTS_SUPERPOSED_HPP
|
|
|
|
#define SPROUT_COMPOST_EFFECTS_SUPERPOSED_HPP
|
2012-11-08 16:09:49 +00:00
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/functional/plus.hpp>
|
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
#include <sprout/utility/value_holder.hpp>
|
2012-11-24 16:05:11 +00:00
|
|
|
#include <sprout/utility/lvalue_forward.hpp>
|
|
|
|
#include <sprout/type_traits/lvalue_reference.hpp>
|
2012-11-08 16:09:49 +00:00
|
|
|
#include <sprout/range/adaptor/transformed.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace compost {
|
|
|
|
namespace effects {
|
|
|
|
//
|
2012-11-17 12:47:52 +00:00
|
|
|
// superpose_holder
|
2012-11-08 16:09:49 +00:00
|
|
|
//
|
|
|
|
template<typename RRange>
|
2012-11-17 12:47:52 +00:00
|
|
|
class superpose_holder {
|
2012-11-08 16:09:49 +00:00
|
|
|
public:
|
|
|
|
typedef RRange range2_type;
|
|
|
|
private:
|
|
|
|
sprout::value_holder<range2_type&> range_;
|
|
|
|
public:
|
2012-11-17 12:47:52 +00:00
|
|
|
superpose_holder() = default;
|
|
|
|
superpose_holder(superpose_holder const&) = default;
|
|
|
|
explicit SPROUT_CONSTEXPR superpose_holder(range2_type& range)
|
2012-11-08 16:09:49 +00:00
|
|
|
: range_(range)
|
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR range2_type& range() const {
|
|
|
|
return range_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2012-11-17 12:47:52 +00:00
|
|
|
// superposed_forwarder
|
2012-11-08 16:09:49 +00:00
|
|
|
//
|
2012-11-17 12:47:52 +00:00
|
|
|
class superposed_forwarder {
|
2012-11-08 16:09:49 +00:00
|
|
|
public:
|
|
|
|
template<typename RRange>
|
2012-11-17 12:47:52 +00:00
|
|
|
SPROUT_CONSTEXPR sprout::compost::effects::superpose_holder<
|
2012-11-08 16:09:49 +00:00
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
|
|
|
|
>
|
|
|
|
operator()(RRange&& range) {
|
2012-11-17 12:47:52 +00:00
|
|
|
return sprout::compost::effects::superpose_holder<
|
2012-11-08 16:09:49 +00:00
|
|
|
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
|
|
|
|
>(
|
|
|
|
sprout::lvalue_forward<RRange>(range)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2012-11-17 12:47:52 +00:00
|
|
|
// superposed
|
2012-11-08 16:09:49 +00:00
|
|
|
//
|
|
|
|
namespace {
|
2012-12-17 14:10:23 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::superposed_forwarder superposed = {};
|
2012-11-08 16:09:49 +00:00
|
|
|
} // anonymous-namespace
|
|
|
|
|
|
|
|
//
|
|
|
|
// operator|
|
|
|
|
//
|
|
|
|
template<typename Range, typename T>
|
|
|
|
inline SPROUT_CONSTEXPR auto
|
2012-11-17 12:47:52 +00:00
|
|
|
operator|(Range&& lhs, sprout::compost::effects::superpose_holder<T> const& rhs)
|
2012-11-08 16:09:49 +00:00
|
|
|
-> decltype(
|
|
|
|
sprout::forward<Range>(lhs)
|
|
|
|
| sprout::adaptors::transformed(rhs.range(), sprout::plus<>())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::forward<Range>(lhs)
|
|
|
|
| sprout::adaptors::transformed(rhs.range(), sprout::plus<>())
|
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace effects
|
2012-11-24 04:04:02 +00:00
|
|
|
|
|
|
|
using sprout::compost::effects::superposed;
|
2012-11-08 16:09:49 +00:00
|
|
|
} // namespace compost
|
|
|
|
} // namespace sprout
|
|
|
|
|
2012-11-17 12:47:52 +00:00
|
|
|
#endif // #ifndef SPROUT_COMPOST_EFFECTS_SUPERPOSED_HPP
|