|
||||
File indexing completed on 2025-01-18 09:38:16
0001 /*============================================================================= 0002 Copyright (c) 2014 Paul Fultz II 0003 mutable.h 0004 Distributed under the Boost Software License, Version 1.0. (See accompanying 0005 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 ==============================================================================*/ 0007 0008 #ifndef BOOST_HOF_GUARD_FUNCTION_MUTABLE_H 0009 #define BOOST_HOF_GUARD_FUNCTION_MUTABLE_H 0010 0011 /// mutable 0012 /// ======= 0013 /// 0014 /// Description 0015 /// ----------- 0016 /// 0017 /// The `mutable` function adaptor allows using a non-const function object 0018 /// inside of a const-function object. In Fit, all the function adaptors use 0019 /// `const` call overloads, so if there is a function that has a non-const 0020 /// call operator, it couldn't be used directly. So, `mutable_` allows the 0021 /// function to be used inside of the call operator. 0022 /// 0023 /// NOTE: This function should be used with caution since many functions are 0024 /// copied, so relying on some internal shared state can be error-prone. 0025 /// 0026 /// Synopsis 0027 /// -------- 0028 /// 0029 /// template<class F> 0030 /// mutable_adaptor<F> mutable_(F f) 0031 /// 0032 /// Requirements 0033 /// ------------ 0034 /// 0035 /// F must be: 0036 /// 0037 /// * [MutableFunctionObject](MutableFunctionObject) 0038 /// * MoveConstructible 0039 /// 0040 0041 #include <boost/hof/detail/result_of.hpp> 0042 #include <boost/hof/detail/delegate.hpp> 0043 #include <boost/hof/detail/move.hpp> 0044 #include <boost/hof/detail/make.hpp> 0045 #include <boost/hof/detail/static_const_var.hpp> 0046 0047 namespace boost { namespace hof { 0048 0049 template<class F> 0050 struct mutable_adaptor 0051 { 0052 mutable F f; 0053 0054 BOOST_HOF_DELEGATE_CONSTRUCTOR(mutable_adaptor, F, f); 0055 0056 BOOST_HOF_RETURNS_CLASS(mutable_adaptor); 0057 0058 template<class... Ts> 0059 BOOST_HOF_SFINAE_RESULT(F, id_<Ts>...) 0060 operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS(BOOST_HOF_CONST_THIS->f(BOOST_HOF_FORWARD(Ts)(xs)...)); 0061 }; 0062 0063 BOOST_HOF_DECLARE_STATIC_VAR(mutable_, detail::make<mutable_adaptor>); 0064 0065 }} // namespace boost::hof 0066 0067 0068 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |