/*============================================================================= 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_FUNCTIONAL_NOT2_HPP #define SPROUT_FUNCTIONAL_NOT2_HPP #include #include #include #include #include namespace sprout { namespace detail { template::value> class binary_negate_impl; template class binary_negate_impl { public: typedef typename Predicate::first_argument_type first_argument_type; typedef typename Predicate::second_argument_type second_argument_type; typedef bool result_type; protected: Predicate fn; public: explicit SPROUT_CONSTEXPR binary_negate_impl(Predicate const& pred) : fn(pred) {} SPROUT_CONSTEXPR bool operator()(typename Predicate::first_argument_type const& x, typename Predicate::second_argument_type const& y) const { return !fn(x, y); } }; template class binary_negate_impl { protected: Predicate fn; public: explicit SPROUT_CONSTEXPR binary_negate_impl(Predicate const& pred) : fn(pred) {} template SPROUT_CONSTEXPR decltype(!std::declval()(std::declval(), std::declval())) operator()(T&& x, U&& y) const { return !fn(sprout::forward(x), sprout::forward(y)); } }; } // namespace detail // 20.8.8 negators template class binary_negate : public sprout::detail::binary_negate_impl { public: explicit SPROUT_CONSTEXPR binary_negate(Predicate const& pred) : sprout::detail::binary_negate_impl(pred) {} }; template inline SPROUT_CONSTEXPR sprout::binary_negate not2(Predicate const& pred) { return sprout::binary_negate(pred); } } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_NOT2_HPP