From 37efd60dc96efffcb623bafc12a1636836794b77 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Mon, 30 Dec 2002 08:12:55 +0000 Subject: [PATCH] for_each reference_wrapper support [SVN r16719] --- include/boost/mpl/aux_/unwrap.hpp | 46 +++++++++++++++++++++++++++++++ include/boost/mpl/for_each.hpp | 34 ++++++++++++----------- 2 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 include/boost/mpl/aux_/unwrap.hpp diff --git a/include/boost/mpl/aux_/unwrap.hpp b/include/boost/mpl/aux_/unwrap.hpp new file mode 100644 index 0000000..71b1a66 --- /dev/null +++ b/include/boost/mpl/aux_/unwrap.hpp @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------- +// boost mpl/aux_/unwrap.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2001 David Abrahams +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +#ifndef BOOST_MPL_AUX_UNWRAP_HPP_INCLUDED +#define BOOST_MPL_AUX_UNWRAP_HPP_INCLUDED + +#include "boost/ref.hpp" + +namespace boost { namespace mpl { namespace aux { + +template< typename F > +inline +F& unwrap(F& f, long) +{ + return f; +} + +template< typename F > +inline +F& +unwrap(reference_wrapper& f, int) +{ + return f; +} + +template< typename F > +inline +F& +unwrap(reference_wrapper const& f, int) +{ + return f; +} + +}}} // namespace boost::mpl::aux + +#endif // BOOST_MPL_AUX_UNWRAP_HPP_INCLUDED diff --git a/include/boost/mpl/for_each.hpp b/include/boost/mpl/for_each.hpp index f00ba12..524453a 100644 --- a/include/boost/mpl/for_each.hpp +++ b/include/boost/mpl/for_each.hpp @@ -21,8 +21,10 @@ #include "boost/mpl/apply.hpp" #include "boost/mpl/bool_c.hpp" #include "boost/mpl/lambda.hpp" +#include "boost/mpl/aux_/unwrap.hpp" + #include "boost/type_traits/is_same.hpp" -#include +#include "boost/utility/value_init.hpp" namespace boost { namespace mpl { @@ -33,13 +35,13 @@ template struct for_each_impl { template< - typename Iterator - , typename LastIterator - , typename TransformFunc - , typename F - > + typename Iterator + , typename LastIterator + , typename TransformFunc + , typename F + > static void execute( - Iterator* + Iterator* , LastIterator* , TransformFunc* , F @@ -52,13 +54,13 @@ template <> struct for_each_impl { template< - typename Iterator - , typename LastIterator - , typename TransformFunc - , typename F - > + typename Iterator + , typename LastIterator + , typename TransformFunc + , typename F + > static void execute( - Iterator* + Iterator* , LastIterator* , TransformFunc* , F f @@ -70,7 +72,7 @@ struct for_each_impl // dwa 2002/9/10 -- make sure not to invoke undefined behavior // when we pass arg. value_initialized x; - f(get(x)); + aux::unwrap(f, 0)(get(x)); typedef typename Iterator::next iter; for_each_impl::value>::execute( @@ -78,10 +80,10 @@ struct for_each_impl } }; -// agurt, 17/mar/02: pointer default parameters are necessary to workaround -// MSVC 6.5 function template signature's mangling bug } // namespace aux +// agurt, 17/mar/02: pointer default parameters are necessary to workaround +// MSVC 6.5 function template signature's mangling bug template< typename Sequence , typename TransformOp