1 /*! 2 @file 3 Forward declares `boost::hana::while_`. 4 5 @copyright Louis Dionne 2013-2017 6 Distributed under the Boost Software License, Version 1.0. 7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 8 */ 9 10 #ifndef BOOST_HANA_FWD_WHILE_HPP 11 #define BOOST_HANA_FWD_WHILE_HPP 12 13 #include <boost/hana/config.hpp> 14 #include <boost/hana/core/when.hpp> 15 16 17 BOOST_HANA_NAMESPACE_BEGIN 18 //! Apply a function to an initial state while some predicate is satisfied. 19 //! @ingroup group-Logical 20 //! 21 //! This method is a natural extension of the `while` language construct 22 //! to manipulate a state whose type may change from one iteration to 23 //! another. However, note that having a state whose type changes from 24 //! one iteration to the other is only possible as long as the predicate 25 //! returns a `Logical` whose truth value is known at compile-time. 26 //! 27 //! Specifically, `while_(pred, state, f)` is equivalent to 28 //! @code 29 //! f(...f(f(state))) 30 //! @endcode 31 //! where `f` is iterated as long as `pred(f(...))` is a true-valued 32 //! `Logical`. 33 //! 34 //! 35 //! @param pred 36 //! A predicate called on the state or on the result of applying `f` a 37 //! certain number of times to the state, and returning whether `f` 38 //! should be applied one more time. 39 //! 40 //! @param state 41 //! The initial state on which `f` is applied. 42 //! 43 //! @param f 44 //! A function that is iterated on the initial state. Note that the 45 //! return type of `f` may change from one iteration to the other, 46 //! but only while `pred` returns a compile-time `Logical`. In other 47 //! words, `decltype(f(stateN))` may differ from `decltype(f(stateN+1))`, 48 //! but only if `pred(f(stateN))` returns a compile-time `Logical`. 49 //! 50 //! 51 //! Example 52 //! ------- 53 //! @include example/while.cpp 54 #ifdef BOOST_HANA_DOXYGEN_INVOKED 55 constexpr auto while_ = [](auto&& pred, auto&& state, auto&& f) -> decltype(auto) { 56 return tag-dispatched; 57 }; 58 #else 59 template <typename L, typename = void> 60 struct while_impl : while_impl<L, when<true>> { }; 61 62 struct while_t { 63 template <typename Pred, typename State, typename F> 64 constexpr decltype(auto) operator()(Pred&& pred, State&& state, F&& f) const; 65 }; 66 67 constexpr while_t while_{}; 68 #endif 69 BOOST_HANA_NAMESPACE_END 70 71 #endif // !BOOST_HANA_FWD_WHILE_HPP 72