1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/compost/effects/clipped.hpp

95 lines
2.7 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2015-01-10 10:13:57 +00:00
Copyright (c) 2011-2015 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
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)
=============================================================================*/
2012-11-17 09:44:24 +00:00
#ifndef SPROUT_COMPOST_EFFECTS_CLIPPED_HPP
#define SPROUT_COMPOST_EFFECTS_CLIPPED_HPP
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/range/adaptor/clamped.hpp>
namespace sprout {
namespace compost {
namespace effects {
//
// clip_holder
//
template<typename T>
class clip_holder {
public:
typedef T value_type;
private:
value_type low_;
value_type up_;
public:
2014-01-13 15:18:06 +00:00
SPROUT_CONSTEXPR clip_holder() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL
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<typename T = double>
SPROUT_CONSTEXPR sprout::compost::effects::clip_holder<T>
2013-02-19 17:23:20 +00:00
operator()(T const& low = -1, T const& up = 1) const {
return sprout::compost::effects::clip_holder<T>(low, up);
}
};
//
// clipped
//
namespace {
2012-12-17 14:10:23 +00:00
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::clipped_forwarder clipped = {};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename T>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::clip_holder<T> const& rhs)
-> decltype(
SPROUT_FORWARD(Range, lhs)
| sprout::adaptors::clamped(rhs.lower(), rhs.upper())
)
{
return SPROUT_FORWARD(Range, lhs)
| sprout::adaptors::clamped(rhs.lower(), rhs.upper())
;
}
template<typename Range>
inline SPROUT_CONSTEXPR auto
2013-07-22 13:00:09 +00:00
operator|(Range&& lhs, sprout::compost::effects::clipped_forwarder const&)
-> decltype(
SPROUT_FORWARD(Range, lhs)
| sprout::adaptors::clamped(-1., 1.)
)
{
return SPROUT_FORWARD(Range, lhs)
| sprout::adaptors::clamped(-1., 1.)
;
}
} // namespace effects
using sprout::compost::effects::clipped;
} // namespace compost
} // namespace sprout
2012-11-17 09:44:24 +00:00
#endif // #ifndef SPROUT_COMPOST_EFFECTS_CLIPPED_HPP