/*============================================================================= Copyright (c) 2011-2014 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_COMPOST_EFFECTS_CLIPPED_HPP #define SPROUT_COMPOST_EFFECTS_CLIPPED_HPP #include #include #include namespace sprout { namespace compost { namespace effects { // // clip_holder // template class clip_holder { public: typedef T value_type; private: value_type low_; value_type up_; public: clip_holder() = default; clip_holder(clip_holder const&) = default; explicit SPROUT_CONSTEXPR clip_holder(value_type const& low = -1, value_type const& up = 1) : low_(low), up_(up) {} SPROUT_CONSTEXPR value_type const& lower() const { return low_; } SPROUT_CONSTEXPR value_type const& upper() const { return up_; } }; // // clipped_forwarder // class clipped_forwarder { public: template SPROUT_CONSTEXPR sprout::compost::effects::clip_holder operator()(T const& low = -1, T const& up = 1) const { return sprout::compost::effects::clip_holder(low, up); } }; // // clipped // namespace { SPROUT_STATIC_CONSTEXPR sprout::compost::effects::clipped_forwarder clipped = {}; } // anonymous-namespace // // operator| // template inline SPROUT_CONSTEXPR auto operator|(Range&& lhs, sprout::compost::effects::clip_holder const& rhs) -> decltype( sprout::forward(lhs) | sprout::adaptors::clamped(rhs.lower(), rhs.upper()) ) { return sprout::forward(lhs) | sprout::adaptors::clamped(rhs.lower(), rhs.upper()) ; } template inline SPROUT_CONSTEXPR auto operator|(Range&& lhs, sprout::compost::effects::clipped_forwarder const&) -> decltype( sprout::forward(lhs) | sprout::adaptors::clamped(-1., 1.) ) { return sprout::forward(lhs) | sprout::adaptors::clamped(-1., 1.) ; } } // namespace effects using sprout::compost::effects::clipped; } // namespace compost } // namespace sprout #endif // #ifndef SPROUT_COMPOST_EFFECTS_CLIPPED_HPP