/*============================================================================= Copyright (c) 2011-2019 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_WAVES_WHITE_NOISE_HPP #define SPROUT_COMPOST_WAVES_WHITE_NOISE_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace compost { namespace waves { // // white_noise_range // template class white_noise_range : public sprout::adaptors::detail::adapted_range_default< Range, sprout::generator_iterator< sprout::random::random_result > > > { public: typedef sprout::adaptors::detail::adapted_range_default< Range, sprout::generator_iterator< sprout::random::random_result > > > base_type; typedef typename base_type::range_type range_type; typedef typename base_type::iterator iterator; typedef typename base_type::value_type value_type; typedef typename iterator::generator_type generator_type; typedef typename generator_type::engine_type engine_type; typedef typename generator_type::distribution_type distribution_type; public: SPROUT_CONSTEXPR white_noise_range() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL white_noise_range(white_noise_range const&) = default; explicit SPROUT_CONSTEXPR white_noise_range( range_type& range, engine_type const& gen, value_type const& sigma = 1 ) : base_type( iterator(distribution_type(0, sigma)(gen), sprout::size(range)), iterator() ) {} SPROUT_CONSTEXPR engine_type engine() const { return base_type::begin().generator().engine(); } SPROUT_CONSTEXPR value_type sigma() const { return base_type::begin().generator().distribution().sigma(); } }; template class white_noise_range : public sprout::range::range_container< sprout::generator_iterator< sprout::random::random_result > > > { public: typedef sprout::range::range_container< sprout::generator_iterator< sprout::random::random_result > > > base_type; typedef typename base_type::iterator iterator; typedef typename base_type::value_type value_type; typedef typename iterator::generator_type generator_type; typedef typename generator_type::engine_type engine_type; typedef typename generator_type::distribution_type distribution_type; public: SPROUT_CONSTEXPR white_noise_range() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL white_noise_range(white_noise_range const&) = default; explicit SPROUT_CONSTEXPR white_noise_range( engine_type const& gen, value_type const& sigma = 1 ) : base_type( iterator(distribution_type(0, sigma)(gen)), iterator() ) {} SPROUT_CONSTEXPR engine_type engine() const { return base_type::begin().generator().engine(); } SPROUT_CONSTEXPR value_type sigma() const { return base_type::begin().generator().distribution().sigma(); } }; // // white_noise_forwarder // class white_noise_forwarder { public: template SPROUT_CONSTEXPR sprout::compost::waves::white_noise_range operator()( UniformRandomNumberGenerator const& gen, Value const& sigma = 1 ) const { return sprout::compost::waves::white_noise_range(gen, sigma); } }; // // white_noise // namespace { SPROUT_STATIC_CONSTEXPR sprout::compost::waves::white_noise_forwarder white_noise = {}; } // anonymous-namespace // // operator| // template inline SPROUT_CONSTEXPR sprout::compost::waves::white_noise_range< Value, UniformRandomNumberGenerator, typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::compost::waves::white_noise_range const& rhs) { return sprout::compost::waves::white_noise_range< Value, UniformRandomNumberGenerator, typename std::remove_reference::type>::type >( sprout::lvalue_forward(lhs), rhs.engine(), rhs.sigma() ); } } // namespace waves using sprout::compost::waves::white_noise; } // namespace compost // // container_construct_traits // template struct container_construct_traits > : public sprout::container_construct_traits::base_type> {}; } // namespace sprout #endif // #ifndef SPROUT_COMPOST_WAVES_WHITE_NOISE_HPP