|
|
|||
File indexing completed on 2025-12-15 09:53:05
0001 /*! 0002 @file 0003 Forward declares `boost::hana::while_`. 0004 0005 Copyright Louis Dionne 2013-2022 0006 Distributed under the Boost Software License, Version 1.0. 0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 0008 */ 0009 0010 #ifndef BOOST_HANA_FWD_WHILE_HPP 0011 #define BOOST_HANA_FWD_WHILE_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/core/when.hpp> 0015 0016 0017 namespace boost { namespace hana { 0018 //! Apply a function to an initial state while some predicate is satisfied. 0019 //! @ingroup group-Logical 0020 //! 0021 //! This method is a natural extension of the `while` language construct 0022 //! to manipulate a state whose type may change from one iteration to 0023 //! another. However, note that having a state whose type changes from 0024 //! one iteration to the other is only possible as long as the predicate 0025 //! returns a `Logical` whose truth value is known at compile-time. 0026 //! 0027 //! Specifically, `while_(pred, state, f)` is equivalent to 0028 //! @code 0029 //! f(...f(f(state))) 0030 //! @endcode 0031 //! where `f` is iterated as long as `pred(f(...))` is a true-valued 0032 //! `Logical`. 0033 //! 0034 //! 0035 //! @param pred 0036 //! A predicate called on the state or on the result of applying `f` a 0037 //! certain number of times to the state, and returning whether `f` 0038 //! should be applied one more time. 0039 //! 0040 //! @param state 0041 //! The initial state on which `f` is applied. 0042 //! 0043 //! @param f 0044 //! A function that is iterated on the initial state. Note that the 0045 //! return type of `f` may change from one iteration to the other, 0046 //! but only while `pred` returns a compile-time `Logical`. In other 0047 //! words, `decltype(f(stateN))` may differ from `decltype(f(stateN+1))`, 0048 //! but only if `pred(f(stateN))` returns a compile-time `Logical`. 0049 //! 0050 //! 0051 //! Example 0052 //! ------- 0053 //! @include example/while.cpp 0054 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0055 constexpr auto while_ = [](auto&& pred, auto&& state, auto&& f) -> decltype(auto) { 0056 return tag-dispatched; 0057 }; 0058 #else 0059 template <typename L, typename = void> 0060 struct while_impl : while_impl<L, when<true>> { }; 0061 0062 struct while_t { 0063 template <typename Pred, typename State, typename F> 0064 constexpr decltype(auto) operator()(Pred&& pred, State&& state, F&& f) const; 0065 }; 0066 0067 BOOST_HANA_INLINE_VARIABLE constexpr while_t while_{}; 0068 #endif 0069 }} // end namespace boost::hana 0070 0071 #endif // !BOOST_HANA_FWD_WHILE_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|