Sprout/sprout/compost/effects/rectified.hpp

76 lines
2 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2014-01-08 07:48:12 +00:00
Copyright (c) 2011-2014 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_RECTIFIED_HPP
#define SPROUT_COMPOST_EFFECTS_RECTIFIED_HPP
2012-11-09 13:33:11 +00:00
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/range/adaptor/transformed.hpp>
namespace sprout {
namespace compost {
//
// rectify_value
//
template<typename T = void>
struct rectify_value {
public:
typedef T argument_type;
typedef T result_type;
public:
SPROUT_CONSTEXPR T
operator()(T const& x) const {
return x < 0 ? -x : x;
}
};
template<>
struct rectify_value<void> {
public:
template<typename T>
SPROUT_CONSTEXPR T
operator()(T const& x) const {
return sprout::compost::rectify_value<T>()(x);
}
};
namespace effects {
//
// rectified_forwarder
//
class rectified_forwarder {};
//
// rectified
//
namespace {
2012-12-17 14:10:23 +00:00
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::rectified_forwarder rectified = {};
2012-11-09 13:33:11 +00:00
} // anonymous-namespace
//
// operator|
//
template<typename Range>
inline SPROUT_CONSTEXPR auto
2013-07-22 13:00:09 +00:00
operator|(Range&& lhs, sprout::compost::effects::rectified_forwarder const&)
2012-11-09 13:33:11 +00:00
-> decltype(
sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::compost::rectify_value<>())
)
{
return sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::compost::rectify_value<>())
;
}
} // namespace effects
using sprout::compost::effects::rectified;
2012-11-09 13:33:11 +00:00
} // namespace compost
} // namespace sprout
2012-11-17 09:44:24 +00:00
#endif // #ifndef SPROUT_COMPOST_EFFECTS_RECTIFIED_HPP