1 // TR1 functional header -*- C++ -*-
3 // Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file tr1/functional
31 * This is a TR1 C++ Library header.
34 #ifndef _TR1_FUNCTIONAL
35 #define _TR1_FUNCTIONAL 1
37 #pragma GCC system_header
39 #include "../functional"
41 #include <tr1/type_traits>
42 #include <ext/type_traits.h>
43 #include <cstdlib> // for std::abort
48 _GLIBCXX_BEGIN_NAMESPACE(tr1)
50 template<typename _MemberPointer>
55 * Actual implementation of _Has_result_type, which uses SFINAE to
56 * determine if the type _Tp has a publicly-accessible member type
60 template<typename _Tp>
61 class _Has_result_type_helper : __sfinae_types
63 template<typename _Up>
67 template<typename _Up>
68 static __one __test(_Wrap_type<typename _Up::result_type>*);
70 template<typename _Up>
71 static __two __test(...);
74 static const bool value = sizeof(__test<_Tp>(0)) == 1;
77 template<typename _Tp>
78 struct _Has_result_type
81 _Has_result_type_helper<typename remove_cv<_Tp>::type>::value>
86 * If we have found a result_type, extract it.
89 template<bool _Has_result_type, typename _Functor>
90 struct _Maybe_get_result_type
93 template<typename _Functor>
94 struct _Maybe_get_result_type<true, _Functor>
96 typedef typename _Functor::result_type result_type;
101 * Base class for any function object that has a weak result type, as
102 * defined in 3.3/3 of TR1.
105 template<typename _Functor>
106 struct _Weak_result_type_impl
107 : _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor>
113 * Strip top-level cv-qualifiers from the function object and let
114 * _Weak_result_type_impl perform the real work.
117 template<typename _Functor>
118 struct _Weak_result_type
119 : _Weak_result_type_impl<typename remove_cv<_Functor>::type>
123 template<typename _Signature>
128 * Actual implementation of result_of. When _Has_result_type is
129 * true, gets its result from _Weak_result_type. Otherwise, uses
130 * the function object's member template result to extract the
134 template<bool _Has_result_type, typename _Signature>
135 struct _Result_of_impl;
137 // Handle member data pointers using _Mem_fn's logic
138 template<typename _Res, typename _Class, typename _T1>
139 struct _Result_of_impl<false, _Res _Class::*(_T1)>
141 typedef typename _Mem_fn<_Res _Class::*>
142 ::template _Result_type<_T1>::type type;
147 * Determines if the type _Tp derives from unary_function.
150 template<typename _Tp>
151 struct _Derives_from_unary_function : __sfinae_types
154 template<typename _T1, typename _Res>
155 static __one __test(const volatile unary_function<_T1, _Res>*);
157 // It's tempting to change "..." to const volatile void*, but
158 // that fails when _Tp is a function type.
159 static __two __test(...);
162 static const bool value = sizeof(__test((_Tp*)0)) == 1;
167 * Determines if the type _Tp derives from binary_function.
170 template<typename _Tp>
171 struct _Derives_from_binary_function : __sfinae_types
174 template<typename _T1, typename _T2, typename _Res>
175 static __one __test(const volatile binary_function<_T1, _T2, _Res>*);
177 // It's tempting to change "..." to const volatile void*, but
178 // that fails when _Tp is a function type.
179 static __two __test(...);
182 static const bool value = sizeof(__test((_Tp*)0)) == 1;
187 * Turns a function type into a function pointer type
190 template<typename _Tp, bool _IsFunctionType = is_function<_Tp>::value>
191 struct _Function_to_function_pointer
196 template<typename _Tp>
197 struct _Function_to_function_pointer<_Tp, true>
204 * Knowing which of unary_function and binary_function _Tp derives
205 * from, derives from the same and ensures that reference_wrapper
206 * will have a weak result type. See cases below.
209 template<bool _Unary, bool _Binary, typename _Tp>
210 struct _Reference_wrapper_base_impl;
212 // Not a unary_function or binary_function, so try a weak result type
213 template<typename _Tp>
214 struct _Reference_wrapper_base_impl<false, false, _Tp>
215 : _Weak_result_type<_Tp>
218 // unary_function but not binary_function
219 template<typename _Tp>
220 struct _Reference_wrapper_base_impl<true, false, _Tp>
221 : unary_function<typename _Tp::argument_type,
222 typename _Tp::result_type>
225 // binary_function but not unary_function
226 template<typename _Tp>
227 struct _Reference_wrapper_base_impl<false, true, _Tp>
228 : binary_function<typename _Tp::first_argument_type,
229 typename _Tp::second_argument_type,
230 typename _Tp::result_type>
233 // both unary_function and binary_function. import result_type to
235 template<typename _Tp>
236 struct _Reference_wrapper_base_impl<true, true, _Tp>
237 : unary_function<typename _Tp::argument_type,
238 typename _Tp::result_type>,
239 binary_function<typename _Tp::first_argument_type,
240 typename _Tp::second_argument_type,
241 typename _Tp::result_type>
243 typedef typename _Tp::result_type result_type;
248 * Derives from unary_function or binary_function when it
249 * can. Specializations handle all of the easy cases. The primary
250 * template determines what to do with a class type, which may
251 * derive from both unary_function and binary_function.
254 template<typename _Tp>
255 struct _Reference_wrapper_base
256 : _Reference_wrapper_base_impl<
257 _Derives_from_unary_function<_Tp>::value,
258 _Derives_from_binary_function<_Tp>::value,
262 // - a function type (unary)
263 template<typename _Res, typename _T1>
264 struct _Reference_wrapper_base<_Res(_T1)>
265 : unary_function<_T1, _Res>
268 // - a function type (binary)
269 template<typename _Res, typename _T1, typename _T2>
270 struct _Reference_wrapper_base<_Res(_T1, _T2)>
271 : binary_function<_T1, _T2, _Res>
274 // - a function pointer type (unary)
275 template<typename _Res, typename _T1>
276 struct _Reference_wrapper_base<_Res(*)(_T1)>
277 : unary_function<_T1, _Res>
280 // - a function pointer type (binary)
281 template<typename _Res, typename _T1, typename _T2>
282 struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>
283 : binary_function<_T1, _T2, _Res>
286 // - a pointer to member function type (unary, no qualifiers)
287 template<typename _Res, typename _T1>
288 struct _Reference_wrapper_base<_Res (_T1::*)()>
289 : unary_function<_T1*, _Res>
292 // - a pointer to member function type (binary, no qualifiers)
293 template<typename _Res, typename _T1, typename _T2>
294 struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>
295 : binary_function<_T1*, _T2, _Res>
298 // - a pointer to member function type (unary, const)
299 template<typename _Res, typename _T1>
300 struct _Reference_wrapper_base<_Res (_T1::*)() const>
301 : unary_function<const _T1*, _Res>
304 // - a pointer to member function type (binary, const)
305 template<typename _Res, typename _T1, typename _T2>
306 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>
307 : binary_function<const _T1*, _T2, _Res>
310 // - a pointer to member function type (unary, volatile)
311 template<typename _Res, typename _T1>
312 struct _Reference_wrapper_base<_Res (_T1::*)() volatile>
313 : unary_function<volatile _T1*, _Res>
316 // - a pointer to member function type (binary, volatile)
317 template<typename _Res, typename _T1, typename _T2>
318 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>
319 : binary_function<volatile _T1*, _T2, _Res>
322 // - a pointer to member function type (unary, const volatile)
323 template<typename _Res, typename _T1>
324 struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>
325 : unary_function<const volatile _T1*, _Res>
328 // - a pointer to member function type (binary, const volatile)
329 template<typename _Res, typename _T1, typename _T2>
330 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>
331 : binary_function<const volatile _T1*, _T2, _Res>
334 template<typename _Tp>
335 class reference_wrapper
336 : public _Reference_wrapper_base<typename remove_cv<_Tp>::type>
338 // If _Tp is a function type, we can't form result_of<_Tp(...)>,
339 // so turn it into a function pointer type.
340 typedef typename _Function_to_function_pointer<_Tp>::type
346 explicit reference_wrapper(_Tp& __indata): _M_data(&__indata)
349 reference_wrapper(const reference_wrapper<_Tp>& __inref):
350 _M_data(__inref._M_data)
354 operator=(const reference_wrapper<_Tp>& __inref)
356 _M_data = __inref._M_data;
360 operator _Tp&() const
361 { return this->get(); }
367 #define _GLIBCXX_REPEAT_HEADER <tr1/ref_wrap_iterate.h>
368 #include <tr1/repeat.h>
369 #undef _GLIBCXX_REPEAT_HEADER
373 // Denotes a reference should be taken to a variable.
374 template<typename _Tp>
375 inline reference_wrapper<_Tp>
377 { return reference_wrapper<_Tp>(__t); }
379 // Denotes a const reference should be taken to a variable.
380 template<typename _Tp>
381 inline reference_wrapper<const _Tp>
383 { return reference_wrapper<const _Tp>(__t); }
385 template<typename _Tp>
386 inline reference_wrapper<_Tp>
387 ref(reference_wrapper<_Tp> __t)
388 { return ref(__t.get()); }
390 template<typename _Tp>
391 inline reference_wrapper<const _Tp>
392 cref(reference_wrapper<_Tp> __t)
393 { return cref(__t.get()); }
395 template<typename _Tp, bool>
396 struct _Mem_fn_const_or_non
398 typedef const _Tp& type;
401 template<typename _Tp>
402 struct _Mem_fn_const_or_non<_Tp, false>
407 template<typename _Res, typename _Class>
408 class _Mem_fn<_Res _Class::*>
410 // This bit of genius is due to Peter Dimov, improved slightly by
412 template<typename _Tp>
414 _M_call(_Tp& __object, _Class *) const
415 { return __object.*__pm; }
417 template<typename _Tp, typename _Up>
419 _M_call(_Tp& __object, _Up * const *) const
420 { return (*__object).*__pm; }
422 template<typename _Tp, typename _Up>
424 _M_call(_Tp& __object, const _Up * const *) const
425 { return (*__object).*__pm; }
427 template<typename _Tp>
429 _M_call(_Tp& __object, const _Class *) const
430 { return __object.*__pm; }
432 template<typename _Tp>
434 _M_call(_Tp& __ptr, const volatile void*) const
435 { return (*__ptr).*__pm; }
437 template<typename _Tp> static _Tp& __get_ref();
439 template<typename _Tp>
440 static __sfinae_types::__one __check_const(_Tp&, _Class*);
441 template<typename _Tp, typename _Up>
442 static __sfinae_types::__one __check_const(_Tp&, _Up * const *);
443 template<typename _Tp, typename _Up>
444 static __sfinae_types::__two __check_const(_Tp&, const _Up * const *);
445 template<typename _Tp>
446 static __sfinae_types::__two __check_const(_Tp&, const _Class*);
447 template<typename _Tp>
448 static __sfinae_types::__two __check_const(_Tp&, const volatile void*);
451 template<typename _Tp>
453 : _Mem_fn_const_or_non<
455 (sizeof(__sfinae_types::__two)
456 == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))>
459 template<typename _Signature>
462 template<typename _CVMem, typename _Tp>
463 struct result<_CVMem(_Tp)>
464 : public _Result_type<_Tp> { };
466 template<typename _CVMem, typename _Tp>
467 struct result<_CVMem(_Tp&)>
468 : public _Result_type<_Tp> { };
470 explicit _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { }
473 _Res& operator()(_Class& __object) const
474 { return __object.*__pm; }
476 const _Res& operator()(const _Class& __object) const
477 { return __object.*__pm; }
480 _Res& operator()(_Class* __object) const
481 { return __object->*__pm; }
484 operator()(const _Class* __object) const
485 { return __object->*__pm; }
487 // Handle smart pointers and derived
488 template<typename _Tp>
489 typename _Result_type<_Tp>::type
490 operator()(_Tp& __unknown) const
491 { return _M_call(__unknown, &__unknown); }
498 * @brief Returns a function object that forwards to the member
501 template<typename _Tp, typename _Class>
502 inline _Mem_fn<_Tp _Class::*>
503 mem_fn(_Tp _Class::* __pm)
505 return _Mem_fn<_Tp _Class::*>(__pm);
509 * @brief Determines if the given type _Tp is a function object
510 * should be treated as a subexpression when evaluating calls to
511 * function objects returned by bind(). [TR1 3.6.1]
513 template<typename _Tp>
514 struct is_bind_expression
515 { static const bool value = false; };
517 template<typename _Tp>
518 const bool is_bind_expression<_Tp>::value;
521 * @brief Determines if the given type _Tp is a placeholder in a
522 * bind() expression and, if so, which placeholder it is. [TR1 3.6.2]
524 template<typename _Tp>
525 struct is_placeholder
526 { static const int value = 0; };
528 template<typename _Tp>
529 const int is_placeholder<_Tp>::value;
533 * The type of placeholder objects defined by libstdc++.
536 template<int _Num> struct _Placeholder { };
540 * Partial specialization of is_placeholder that provides the placeholder
541 * number for the placeholder objects defined by libstdc++.
545 struct is_placeholder<_Placeholder<_Num> >
546 { static const int value = _Num; };
549 const int is_placeholder<_Placeholder<_Num> >::value;
553 * Maps an argument to bind() into an actual argument to the bound
554 * function object [TR1 3.6.3/5]. Only the first parameter should
555 * be specified: the rest are used to determine among the various
556 * implementations. Note that, although this class is a function
557 * object, isn't not entirely normal because it takes only two
558 * parameters regardless of the number of parameters passed to the
559 * bind expression. The first parameter is the bound argument and
560 * the second parameter is a tuple containing references to the
561 * rest of the arguments.
564 template<typename _Arg,
565 bool _IsBindExp = is_bind_expression<_Arg>::value,
566 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
571 * If the argument is reference_wrapper<_Tp>, returns the
572 * underlying reference. [TR1 3.6.3/5 bullet 1]
575 template<typename _Tp>
576 class _Mu<reference_wrapper<_Tp>, false, false>
579 typedef _Tp& result_type;
581 /* Note: This won't actually work for const volatile
582 * reference_wrappers, because reference_wrapper::get() is const
583 * but not volatile-qualified. This might be a defect in the TR.
585 template<typename _CVRef, typename _Tuple>
587 operator()(_CVRef& __arg, const _Tuple&) const volatile
588 { return __arg.get(); }
593 * If the argument is a bind expression, we invoke the underlying
594 * function object with the same cv-qualifiers as we are given and
595 * pass along all of our arguments (unwrapped). [TR1 3.6.3/5 bullet 2]
598 template<typename _Arg>
599 class _Mu<_Arg, true, false>
602 template<typename _Signature> class result;
604 #define _GLIBCXX_REPEAT_HEADER <tr1/mu_iterate.h>
605 # include <tr1/repeat.h>
606 #undef _GLIBCXX_REPEAT_HEADER
611 * If the argument is a placeholder for the Nth argument, returns
612 * a reference to the Nth argument to the bind function object.
613 * [TR1 3.6.3/5 bullet 3]
616 template<typename _Arg>
617 class _Mu<_Arg, false, true>
620 template<typename _Signature> class result;
622 template<typename _CVMu, typename _CVArg, typename _Tuple>
623 class result<_CVMu(_CVArg, _Tuple)>
625 // Add a reference, if it hasn't already been done for us.
626 // This allows us to be a little bit sloppy in constructing
627 // the tuple that we pass to result_of<...>.
628 typedef typename tuple_element<(is_placeholder<_Arg>::value - 1),
629 _Tuple>::type __base_type;
632 typedef typename add_reference<__base_type>::type type;
635 template<typename _Tuple>
636 typename result<_Mu(_Arg, _Tuple)>::type
637 operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile
639 return ::std::tr1::get<(is_placeholder<_Arg>::value - 1)>(__tuple);
645 * If the argument is just a value, returns a reference to that
646 * value. The cv-qualifiers on the reference are the same as the
647 * cv-qualifiers on the _Mu object. [TR1 3.6.3/5 bullet 4]
650 template<typename _Arg>
651 class _Mu<_Arg, false, false>
654 template<typename _Signature> struct result;
656 template<typename _CVMu, typename _CVArg, typename _Tuple>
657 struct result<_CVMu(_CVArg, _Tuple)>
659 typedef typename add_reference<_CVArg>::type type;
662 // Pick up the cv-qualifiers of the argument
663 template<typename _CVArg, typename _Tuple>
664 _CVArg& operator()(_CVArg& __arg, const _Tuple&) const volatile
670 * Maps member pointers into instances of _Mem_fn but leaves all
671 * other function objects untouched. Used by tr1::bind(). The
672 * primary template handles the non--member-pointer case.
675 template<typename _Tp>
676 struct _Maybe_wrap_member_pointer
679 static const _Tp& __do_wrap(const _Tp& __x) { return __x; }
684 * Maps member pointers into instances of _Mem_fn but leaves all
685 * other function objects untouched. Used by tr1::bind(). This
686 * partial specialization handles the member pointer case.
689 template<typename _Tp, typename _Class>
690 struct _Maybe_wrap_member_pointer<_Tp _Class::*>
692 typedef _Mem_fn<_Tp _Class::*> type;
693 static type __do_wrap(_Tp _Class::* __pm) { return type(__pm); }
698 * Type of the function object returned from bind().
701 template<typename _Signature>
706 * Type of the function object returned from bind<R>().
709 template<typename _Result, typename _Signature>
714 * Class template _Bind is always a bind expression.
717 template<typename _Signature>
718 struct is_bind_expression<_Bind<_Signature> >
719 { static const bool value = true; };
721 template<typename _Signature>
722 const bool is_bind_expression<_Bind<_Signature> >::value;
726 * Class template _Bind_result is always a bind expression.
729 template<typename _Result, typename _Signature>
730 struct is_bind_expression<_Bind_result<_Result, _Signature> >
731 { static const bool value = true; };
733 template<typename _Result, typename _Signature>
734 const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value;
737 * @brief Exception class thrown when class template function's
738 * operator() is called with an empty target.
741 class bad_function_call : public std::exception { };
745 * The integral constant expression 0 can be converted into a
746 * pointer to this type. It is used by the function template to
747 * accept NULL pointers.
750 struct _M_clear_type;
754 * Trait identifying "location-invariant" types, meaning that the
755 * address of the object (or any of its members) will not escape.
756 * Also implies a trivial copy constructor and assignment operator.
759 template<typename _Tp>
760 struct __is_location_invariant
761 : integral_constant<bool,
762 (is_pointer<_Tp>::value
763 || is_member_pointer<_Tp>::value)>
767 class _Undefined_class;
772 const void* _M_const_object;
773 void (*_M_function_pointer)();
774 void (_Undefined_class::*_M_member_pointer)();
778 void* _M_access() { return &_M_pod_data[0]; }
779 const void* _M_access() const { return &_M_pod_data[0]; }
781 template<typename _Tp> _Tp& _M_access()
782 { return *static_cast<_Tp*>(_M_access()); }
784 template<typename _Tp> const _Tp& _M_access() const
785 { return *static_cast<const _Tp*>(_M_access()); }
787 _Nocopy_types _M_unused;
788 char _M_pod_data[sizeof(_Nocopy_types)];
791 enum _Manager_operation
799 /* Simple type wrapper that helps avoid annoying const problems
800 when casting between void pointers and pointers-to-pointers. */
801 template<typename _Tp>
802 struct _Simple_type_wrapper
804 _Simple_type_wrapper(_Tp __value) : __value(__value) { }
809 template<typename _Tp>
810 struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
811 : __is_location_invariant<_Tp>
815 // Converts a reference to a function object into a callable
817 template<typename _Functor>
818 inline _Functor& __callable_functor(_Functor& __f) { return __f; }
820 template<typename _Member, typename _Class>
821 inline _Mem_fn<_Member _Class::*>
822 __callable_functor(_Member _Class::* &__p)
823 { return mem_fn(__p); }
825 template<typename _Member, typename _Class>
826 inline _Mem_fn<_Member _Class::*>
827 __callable_functor(_Member _Class::* const &__p)
828 { return mem_fn(__p); }
830 template<typename _Signature, typename _Functor>
831 class _Function_handler;
833 template<typename _Signature>
839 * Base class of all polymorphic function object wrappers.
845 static const std::size_t _M_max_size = sizeof(_Nocopy_types);
846 static const std::size_t _M_max_align = __alignof__(_Nocopy_types);
848 template<typename _Functor>
852 static const bool __stored_locally =
853 (__is_location_invariant<_Functor>::value
854 && sizeof(_Functor) <= _M_max_size
855 && __alignof__(_Functor) <= _M_max_align
856 && (_M_max_align % __alignof__(_Functor) == 0));
857 typedef integral_constant<bool, __stored_locally> _Local_storage;
859 // Retrieve a pointer to the function object
860 static _Functor* _M_get_pointer(const _Any_data& __source)
862 const _Functor* __ptr =
863 __stored_locally? &__source._M_access<_Functor>()
864 /* have stored a pointer */ : __source._M_access<_Functor*>();
865 return const_cast<_Functor*>(__ptr);
868 // Clone a location-invariant function object that fits within
869 // an _Any_data structure.
871 _M_clone(_Any_data& __dest, const _Any_data& __source, true_type)
873 new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
876 // Clone a function object that is not location-invariant or
877 // that cannot fit into an _Any_data structure.
879 _M_clone(_Any_data& __dest, const _Any_data& __source, false_type)
881 __dest._M_access<_Functor*>() =
882 new _Functor(*__source._M_access<_Functor*>());
885 // Destroying a location-invariant object may still require
888 _M_destroy(_Any_data& __victim, true_type)
890 __victim._M_access<_Functor>().~_Functor();
893 // Destroying an object located on the heap.
895 _M_destroy(_Any_data& __victim, false_type)
897 delete __victim._M_access<_Functor*>();
902 _M_manager(_Any_data& __dest, const _Any_data& __source,
903 _Manager_operation __op)
906 case __get_type_info:
907 __dest._M_access<const type_info*>() = &typeid(_Functor);
910 case __get_functor_ptr:
911 __dest._M_access<_Functor*>() = _M_get_pointer(__source);
914 case __clone_functor:
915 _M_clone(__dest, __source, _Local_storage());
918 case __destroy_functor:
919 _M_destroy(__dest, _Local_storage());
926 _M_init_functor(_Any_data& __functor, const _Functor& __f)
928 _M_init_functor(__functor, __f, _Local_storage());
931 template<typename _Signature>
933 _M_not_empty_function(const function<_Signature>& __f)
938 template<typename _Tp>
940 _M_not_empty_function(const _Tp*& __fp)
945 template<typename _Class, typename _Tp>
947 _M_not_empty_function(_Tp _Class::* const& __mp)
952 template<typename _Tp>
954 _M_not_empty_function(const _Tp&)
961 _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type)
963 new (__functor._M_access()) _Functor(__f);
967 _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type)
969 __functor._M_access<_Functor*>() = new _Functor(__f);
973 template<typename _Functor>
974 class _Ref_manager : public _Base_manager<_Functor*>
976 typedef _Function_base::_Base_manager<_Functor*> _Base;
980 _M_manager(_Any_data& __dest, const _Any_data& __source,
981 _Manager_operation __op)
984 case __get_type_info:
985 __dest._M_access<const type_info*>() = &typeid(_Functor);
988 case __get_functor_ptr:
989 __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source);
990 return is_const<_Functor>::value;
994 _Base::_M_manager(__dest, __source, __op);
1000 _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
1002 // TBD: Use address_of function instead
1003 _Base::_M_init_functor(__functor, &__f.get());
1007 _Function_base() : _M_manager(0) { }
1013 _M_manager(_M_functor, _M_functor, __destroy_functor);
1018 bool _M_empty() const { return !_M_manager; }
1020 typedef bool (*_Manager_type)(_Any_data&, const _Any_data&,
1021 _Manager_operation);
1023 _Any_data _M_functor;
1024 _Manager_type _M_manager;
1027 // [3.7.2.7] null pointer comparisons
1030 * @brief Compares a polymorphic function object wrapper against 0
1031 * (the NULL pointer).
1032 * @returns @c true if the wrapper has no target, @c false otherwise
1034 * This function will not throw an exception.
1036 template<typename _Signature>
1038 operator==(const function<_Signature>& __f, _M_clear_type*)
1046 template<typename _Signature>
1048 operator==(_M_clear_type*, const function<_Signature>& __f)
1054 * @brief Compares a polymorphic function object wrapper against 0
1055 * (the NULL pointer).
1056 * @returns @c false if the wrapper has no target, @c true otherwise
1058 * This function will not throw an exception.
1060 template<typename _Signature>
1062 operator!=(const function<_Signature>& __f, _M_clear_type*)
1070 template<typename _Signature>
1072 operator!=(_M_clear_type*, const function<_Signature>& __f)
1077 // [3.7.2.8] specialized algorithms
1080 * @brief Swap the targets of two polymorphic function object wrappers.
1082 * This function will not throw an exception.
1084 template<typename _Signature>
1086 swap(function<_Signature>& __x, function<_Signature>& __y)
1091 _GLIBCXX_END_NAMESPACE
1094 #define _GLIBCXX_JOIN(X,Y) _GLIBCXX_JOIN2( X , Y )
1095 #define _GLIBCXX_JOIN2(X,Y) _GLIBCXX_JOIN3(X,Y)
1096 #define _GLIBCXX_JOIN3(X,Y) X##Y
1097 #define _GLIBCXX_REPEAT_HEADER <tr1/functional_iterate.h>
1098 #include <tr1/repeat.h>
1099 #undef _GLIBCXX_REPEAT_HEADER
1100 #undef _GLIBCXX_JOIN3
1101 #undef _GLIBCXX_JOIN2
1102 #undef _GLIBCXX_JOIN
1104 #include <tr1/functional_hash.h>