From 688df3d1377f2421ad122e55c2ce479856d16230 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 5 Aug 2002 06:19:17 +0000 Subject: [PATCH] function_base.hpp: - Use all: - Add BOOST_FUNCTION_NO_DEPRECATED macro hackery to get rid of ALL deprecated features [SVN r14685] --- include/boost/function.hpp | 217 ++++++++++++++----- include/boost/function/function_base.hpp | 48 +--- include/boost/function/function_template.hpp | 67 +++++- 3 files changed, 220 insertions(+), 112 deletions(-) diff --git a/include/boost/function.hpp b/include/boost/function.hpp index d2f4aae..bad6a4d 100644 --- a/include/boost/function.hpp +++ b/include/boost/function.hpp @@ -36,6 +36,11 @@ #include #include +// Don't compile any of this code if we've asked not to include the deprecated +// syntax and we don't have partial specialization, because none of this code +// can work. +#if !defined (BOOST_FUNCTION_NO_DEPRECATED) || !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + namespace boost { namespace detail { namespace function { @@ -57,13 +62,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function0 type; + typedef function0 type; }; }; @@ -82,13 +93,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function1 type; + typedef function1 type; }; }; @@ -107,13 +124,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function2 type; + typedef function2 type; }; }; @@ -132,13 +155,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function3 type; + typedef function3 type; }; }; @@ -157,13 +186,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function4 type; + typedef function4 type; }; }; @@ -182,13 +217,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function5 + typedef function5 type; }; }; @@ -208,13 +249,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function6 + typedef function6 type; }; }; @@ -234,13 +281,18 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function7 type; }; }; @@ -260,13 +312,18 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function8 type; }; }; @@ -286,14 +343,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { - typedef function9 type; + typedef function9 type; }; }; @@ -312,14 +374,19 @@ namespace boost { typename T8, typename T9, typename T10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator > struct params { typedef function10 type; +#ifndef BOOST_FUNCTION_NO_DEPRECATED + Policy, Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + Allocator> type; }; }; @@ -456,45 +523,12 @@ namespace boost { typename InT8, typename InT9, typename InT10, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename InPolicy, typename InMixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename InAllocator> struct maybe_decode_function_args - { - // Not a function, so just map the types directly - typedef InR R; - typedef InT1 T1; - typedef InT2 T2; - typedef InT3 T3; - typedef InT4 T4; - typedef InT5 T5; - typedef InT6 T6; - typedef InT7 T7; - typedef InT8 T8; - typedef InT9 T9; - typedef InT10 T10; - typedef InPolicy Policy; - typedef InMixin Mixin; - typedef InAllocator Allocator; - }; - - template - struct maybe_decode_function_args { typedef function_traits traits; @@ -509,6 +543,7 @@ namespace boost { typedef typename get_arg8_type<(traits::arity >= 8), traits>::type T8; typedef typename get_arg9_type<(traits::arity >= 9), traits>::type T9; typedef typename get_arg10_type<(traits::arity >= 10), traits>::type T10; +#ifndef BOOST_FUNCTION_NO_DEPRECATED typedef typename ct_if<(is_same::value), empty_function_policy, InT1>::type Policy; @@ -518,8 +553,58 @@ namespace boost { typedef typename ct_if<(is_same::value), std::allocator, InT3>::type Allocator; +#else + typedef typename ct_if<(is_same::value), + std::allocator, + InT1>::type Allocator; +#endif // BOOST_FUNCTION_NO_DEPRECATED }; +#ifndef BOOST_FUNCTION_NO_DEPRECATED + template + struct maybe_decode_function_args + { + // Not a function, so just map the types directly + typedef InR R; + typedef InT1 T1; + typedef InT2 T2; + typedef InT3 T3; + typedef InT4 T4; + typedef InT5 T5; + typedef InT6 T6; + typedef InT7 T7; + typedef InT8 T8; + typedef InT9 T9; + typedef InT10 T10; +#ifndef BOOST_FUNCTION_NO_DEPRECATED + typedef InPolicy Policy; + typedef InMixin Mixin; +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + typedef InAllocator Allocator; + + }; +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + #endif // ndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template< @@ -544,8 +629,10 @@ namespace boost { typedef maybe_decode_function_args<(is_function::value), InR, InT1, InT2, InT3, InT4, InT5, InT6, InT7, InT8, InT9, InT10, - InPolicy, InMixin, InAllocator> - decoder; +#ifndef BOOST_FUNCTION_NO_DEPRECATED + InPolicy, InMixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + InAllocator> decoder; typedef typename decoder::R R; typedef typename decoder::T1 T1; typedef typename decoder::T2 T2; @@ -557,8 +644,10 @@ namespace boost { typedef typename decoder::T8 T8; typedef typename decoder::T9 T9; typedef typename decoder::T10 T10; +#ifndef BOOST_FUNCTION_NO_DEPRECATED typedef typename decoder::Policy Policy; typedef typename decoder::Mixin Mixin; +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typedef typename decoder::Allocator Allocator; #else typedef InR R; @@ -580,10 +669,14 @@ namespace boost { typedef typename real_get_function_impl< (count_used_args::value) >::template params::type +#ifndef BOOST_FUNCTION_NO_DEPRECATED + Policy, Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + Allocator>::type type; }; +#ifndef BOOST_FUNCTION_NO_DEPRECATED template< typename InR, typename InT1, @@ -676,9 +769,9 @@ namespace boost { Allocator>::type type; }; -#endif +#endif // ndef NO_DEPENDENT_NESTED_DERIVATIONS }; - +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED } // end namespace function } // end namespace detail @@ -697,9 +790,11 @@ namespace boost { > class function : public detail::function::get_function_impl::type, - public detail::function::function_traits_builder + T8, T9, T10>::type +#ifndef BOOST_FUNCTION_NO_DEPRECATED + , public detail::function::function_traits_builder +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED { typedef typename detail::function::get_function_impl BOOST_FUNCTION_DEPRECATED_PRE - void set(Functor BOOST_FUNCTION_TARGET_FIX(const &) f) + void set(Functor BOOST_FUNCTION_TARGET_FIX(const &) f) { BOOST_FUNCTION_DEPRECATED_INNER self_type(f).swap(*this); } - BOOST_FUNCTION_DEPRECATED_PRE + BOOST_FUNCTION_DEPRECATED_PRE void set(const base_type& f) { BOOST_FUNCTION_DEPRECATED_INNER self_type(f).swap(*this); } - BOOST_FUNCTION_DEPRECATED_PRE + BOOST_FUNCTION_DEPRECATED_PRE void set(const self_type& f) { BOOST_FUNCTION_DEPRECATED_INNER self_type(f).swap(*this); } +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED }; template #include #include +#include #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__ICL) && __ICL <= 600 || defined(__MWERKS__) && __MWERKS__ < 0x2406 # define BOOST_FUNCTION_TARGET_FIX(x) x @@ -33,58 +34,15 @@ #if defined (BOOST_MSVC) && (BOOST_MSVC >= 1300) # define BOOST_FUNCTION_DEPRECATED_PRE __declspec(deprecated) -# define BOOST_FUNCTION_DEPRECATED_INSIDE +# define BOOST_FUNCTION_DEPRECATED_INNER #else # define BOOST_FUNCTION_DEPRECATED_PRE -# define BOOST_FUNCTION_DEPRECATED_INSIDE int deprecated; +# define BOOST_FUNCTION_DEPRECATED_INNER int deprecated; #endif namespace boost { namespace detail { namespace function { - /* - * The ct_if implementation is temporary code. When a Boost metaprogramming - * library is introduced, Boost.Function will use it instead. - */ - namespace intimate { - struct SelectThen - { - template - struct Result - { - typedef Then type; - }; - }; - - struct SelectElse - { - template - struct Result - { - typedef Else type; - }; - }; - - template - struct Selector - { - typedef SelectThen type; - }; - - template<> - struct Selector - { - typedef SelectElse type; - }; - } // end namespace intimate - - template - struct ct_if - { - typedef typename intimate::Selector::type select; - typedef typename select::template Result::type type; - }; - /** * A union of a function pointer and a void pointer. This is necessary * because 5.2.10/6 allows reinterpret_cast<> to safely cast between diff --git a/include/boost/function/function_template.hpp b/include/boost/function/function_template.hpp index 3ea16c8..c2ff200 100644 --- a/include/boost/function/function_template.hpp +++ b/include/boost/function/function_template.hpp @@ -229,11 +229,16 @@ namespace boost { template< typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS, +#ifndef BOOST_FUNCTION_NO_DEPRECATED typename Policy = empty_function_policy, typename Mixin = empty_function_mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typename Allocator = BOOST_FUNCTION_DEFAULT_ALLOCATOR > - class BOOST_FUNCTION_FUNCTION : public function_base, public Mixin + class BOOST_FUNCTION_FUNCTION : public function_base +#ifndef BOOST_FUNCTION_NO_DEPRECATED + , public Mixin +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED { typedef typename detail::function::function_return_type::type internal_result_type; @@ -253,36 +258,58 @@ namespace boost { #else typedef internal_result_type result_type; #endif // BOOST_NO_VOID_RETURNS +#ifndef BOOST_FUNCTION_NO_DEPRECATED typedef Policy policy_type; typedef Mixin mixin_type; +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED typedef Allocator allocator_type; typedef BOOST_FUNCTION_FUNCTION self_type; - BOOST_FUNCTION_FUNCTION() : function_base(), Mixin(), invoker(0) {} + BOOST_FUNCTION_FUNCTION() : function_base() +#ifndef BOOST_FUNCTION_NO_DEPRECATED + , Mixin() +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + , invoker(0) {} +#ifndef BOOST_FUNCTION_NO_DEPRECATED explicit BOOST_FUNCTION_FUNCTION(const Mixin& m) : - function_base(), Mixin(m), invoker(0) + function_base(), + Mixin(m), + invoker(0) { } +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED // MSVC chokes if the following two constructors are collapsed into // one with a default parameter. template BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f) : - function_base(), Mixin(), invoker(0) + function_base(), +#ifndef BOOST_FUNCTION_NO_DEPRECATED + Mixin(), +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + invoker(0) { this->assign_to(f); } +#ifndef BOOST_FUNCTION_NO_DEPRECATED template BOOST_FUNCTION_FUNCTION(Functor f, const Mixin& m) : - function_base(), Mixin(m), invoker(0) + function_base(), + Mixin(m), + invoker(0) { this->assign_to(f); } +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED BOOST_FUNCTION_FUNCTION(const BOOST_FUNCTION_FUNCTION& f) : - function_base(), Mixin(static_cast(f)), invoker(0) + function_base(), +#ifndef BOOST_FUNCTION_NO_DEPRECATED + Mixin(static_cast(f)), +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + invoker(0) { this->assign_to_own(f); } @@ -293,14 +320,19 @@ namespace boost { { assert(!this->empty()); +#ifndef BOOST_FUNCTION_NO_DEPRECATED policy_type policy; policy.precall(this); +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED internal_result_type result = invoker(function_base::functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS); +#ifndef BOOST_FUNCTION_NO_DEPRECATED policy.postcall(this); +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + #ifndef BOOST_NO_VOID_RETURNS return static_cast(result); #else @@ -317,17 +349,23 @@ namespace boost { BOOST_FUNCTION_FUNCTION& operator=(Functor BOOST_FUNCTION_TARGET_FIX(const &) f) { +#ifndef BOOST_FUNCTION_NO_DEPRECATED self_type(f, static_cast(*this)).swap(*this); +#else + self_type(f).swap(*this); +#endif // BOOST_FUNCTION_NO_DEPRECATED return *this; } +#ifndef BOOST_FUNCTION_NO_DEPRECATED template - BOOST_FUNCTION_DEPRECATED_PRE + BOOST_FUNCTION_DEPRECATED_PRE void set(Functor BOOST_FUNCTION_TARGET_FIX(const &) f) { BOOST_FUNCTION_DEPRECATED_INNER self_type(f, static_cast(*this)).swap(*this); } +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED // Assignment from another BOOST_FUNCTION_FUNCTION BOOST_FUNCTION_FUNCTION& operator=(const BOOST_FUNCTION_FUNCTION& f) @@ -339,8 +377,9 @@ namespace boost { return *this; } +#ifndef BOOST_FUNCTION_NO_DEPRECATED // Assignment from another BOOST_FUNCTION_FUNCTION - BOOST_FUNCTION_DEPRECATED_PRE + BOOST_FUNCTION_DEPRECATED_PRE void set(const BOOST_FUNCTION_FUNCTION& f) { BOOST_FUNCTION_DEPRECATED_INNER @@ -349,6 +388,7 @@ namespace boost { self_type(f).swap(*this); } +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED void swap(BOOST_FUNCTION_FUNCTION& other) { @@ -358,7 +398,9 @@ namespace boost { std::swap(function_base::manager, other.manager); std::swap(function_base::functor, other.functor); std::swap(invoker, other.invoker); +#ifndef BOOST_FUNCTION_NO_DEPRECATED std::swap(static_cast(*this), static_cast(other)); +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED } // Clear out a target, if there is one @@ -506,19 +548,26 @@ namespace boost { }; template +#ifndef BOOST_FUNCTION_NO_DEPRECATED + typename Policy, typename Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED + typename Allocator> inline void swap(BOOST_FUNCTION_FUNCTION< R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS , +#ifndef BOOST_FUNCTION_NO_DEPRECATED Policy, Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED Allocator >& f1, BOOST_FUNCTION_FUNCTION< R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS, +#ifndef BOOST_FUNCTION_NO_DEPRECATED Policy, Mixin, +#endif // ndef BOOST_FUNCTION_NO_DEPRECATED Allocator >& f2) {