From 0179f2c63218bf1d5d17ef1a7a0698d542f69864 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 24 Feb 2005 01:16:08 +0000 Subject: [PATCH] TR1 mem_fn and function support From-SVN: r95486 --- libstdc++-v3/ChangeLog | 28 + libstdc++-v3/include/Makefile.am | 1 + libstdc++-v3/include/Makefile.in | 1 + libstdc++-v3/include/tr1/functional | 1014 ++++++++++++++++- libstdc++-v3/include/tr1/functional_iterate.h | 700 ++++++++++++ libstdc++-v3/testsuite/testsuite_tr1.h | 75 +- .../tr1/3_function_objects/function/1.cc | 95 ++ .../tr1/3_function_objects/function/2.cc | 78 ++ .../tr1/3_function_objects/function/3.cc | 78 ++ .../tr1/3_function_objects/function/4.cc | 82 ++ .../tr1/3_function_objects/function/5.cc | 107 ++ .../tr1/3_function_objects/function/6.cc | 83 ++ .../tr1/3_function_objects/function/7.cc | 82 ++ .../tr1/3_function_objects/function/8.cc | 148 +++ .../tr1/3_function_objects/function/9.cc | 55 + .../tr1/3_function_objects/mem_fn.cc | 78 ++ 16 files changed, 2675 insertions(+), 30 deletions(-) create mode 100644 libstdc++-v3/include/tr1/functional_iterate.h create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/function/9.cc create mode 100644 libstdc++-v3/testsuite/tr1/3_function_objects/mem_fn.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 14e038d4fa4..ae3e7e4a013 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,31 @@ +2005-02-23 Douglas Gregor + + * include/tr1/functional (function): New class template. + (mem_fn): New function template. + Implementations of TR1 function and mem_fn facilities. + * include/tr1/functional_iterate.h: Implementations of TR1 + function and mem_fn facilities. + * testsuite/tr1/3_function_objects/function/1.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/2.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/3.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/4.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/5.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/6.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/7.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/8.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/function/9.cc: New + test of std::tr1::function. + * testsuite/tr1/3_function_objects/mem_fn.cc: New test of + std::tr1::mem_fn. + 2005-02-23 Paolo Carlini * include/tr1/type_traits: Implement is_convertible. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index ad4930ce921..24da787ece4 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -229,6 +229,7 @@ tr1_builddir = ./tr1 tr1_headers = \ ${tr1_srcdir}/array \ ${tr1_srcdir}/functional \ + ${tr1_srcdir}/functional_iterate.h \ ${tr1_srcdir}/memory \ ${tr1_srcdir}/tuple \ ${tr1_srcdir}/utility \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 50c002413fc..7688b318233 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -445,6 +445,7 @@ tr1_builddir = ./tr1 tr1_headers = \ ${tr1_srcdir}/array \ ${tr1_srcdir}/functional \ + ${tr1_srcdir}/functional_iterate.h \ ${tr1_srcdir}/memory \ ${tr1_srcdir}/tuple \ ${tr1_srcdir}/utility \ diff --git a/libstdc++-v3/include/tr1/functional b/libstdc++-v3/include/tr1/functional index 602946f42c9..e8be4459598 100644 --- a/libstdc++-v3/include/tr1/functional +++ b/libstdc++-v3/include/tr1/functional @@ -27,15 +27,19 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -/** @file - * This is a TR1 C++ Library header. +/** @file + * This is a TR1 C++ Library header. */ #ifndef _TR1_FUNCTIONAL #define _TR1_FUNCTIONAL 1 #include "../functional" -#include // for std::tr1::hash +#include +#include +#include "../bits/cpp_type_traits.h" +#include // for std::tr1::hash +#include // for std::abort namespace std { @@ -49,32 +53,32 @@ namespace tr1 typedef _Tp type; explicit reference_wrapper(_Tp& __indata): _M_data(&__indata) { } - + reference_wrapper(const reference_wrapper<_Tp>& __inref): _M_data(__inref._M_data) { } - reference_wrapper& + reference_wrapper& operator=(const reference_wrapper<_Tp>& __inref) { - _M_data = __inref._M_data; - return *this; + _M_data = __inref._M_data; + return *this; } - + operator _Tp&() const { return this->get(); } - + _Tp& get() const { return *_M_data; } }; - + // Denotes a reference should be taken to a variable. template reference_wrapper<_Tp> ref(_Tp& __t) { return reference_wrapper<_Tp>(__t); } - + // Denotes a const reference should be taken to a variable. template reference_wrapper @@ -89,16 +93,980 @@ namespace tr1 reference_wrapper cref(reference_wrapper<_Tp> __t) { return cref(__t.get()); } + template + class _Mem_fn; + + template + struct _Mem_fn_const_or_non + { + typedef const _Tp& type; + }; + + template + struct _Mem_fn_const_or_non<_Tp, false> + { + typedef _Tp& type; + }; + + template + class _Mem_fn<_Res _Class::*> + { + // This bit of genius is due to Peter Dimov, improved slightly by + // Douglas Gregor. + template + _Res& + _M_call(_Tp& __object, _Class *) const + { return __object.*__pm; } + + template + _Res& + _M_call(_Tp& __object, _Up * const *) const + { return (*__object).*__pm; } + + template + const _Res& + _M_call(_Tp& __object, const _Up * const *) const + { return (*__object).*__pm; } + + template + const _Res& + _M_call(_Tp& __object, const _Class *) const + { return __object.*__pm; } + + template + const _Res& + _M_call(_Tp& __ptr, const volatile void*) const + { return (*__ptr).*__pm; } + + template static _Tp& __get_ref(); + + template + static __sfinae_types::__one __check_const(_Tp&, _Class*); + template + static __sfinae_types::__one __check_const(_Tp&, _Up * const *); + template + static __sfinae_types::__two __check_const(_Tp&, const _Up * const *); + template + static __sfinae_types::__two __check_const(_Tp&, const _Class*); + template + static __sfinae_types::__two __check_const(_Tp&, const volatile void*); + + template + struct _Result_type + : _Mem_fn_const_or_non< + _Res, + (sizeof(__sfinae_types::__two) + == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))> + { }; + + public: + explicit _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { } + + // Handle objects + _Res& operator()(_Class& __object) const + { return __object.*__pm; } + + const _Res& operator()(const _Class& __object) const + { return __object.*__pm; } + + // Handle pointers + _Res& operator()(_Class* __object) const + { return __object->*__pm; } + + const _Res& + operator()(const _Class* __object) const + { return __object->*__pm; } + + // Handle smart pointers and derived + template + typename _Result_type<_Tp>::type + operator()(_Tp& __unknown) const + { return _M_call(__unknown, &__unknown); } + + private: + _Res _Class::*__pm; + }; + + /** + * @brief Returns a function object that forwards to the member + * pointer @a pm. + */ + template + inline _Mem_fn<_T _Class::*> + mem_fn(_T _Class::* __pm) + { + return _Mem_fn<_T _Class::*>(__pm); + } + + /** + * @brief Exception class thrown when class template function's + * operator() is called with an empty target. + * + */ + class bad_function_call : public std::exception { }; + + /** + * @if maint + * The integral constant expression 0 can be converted into a + * pointer to this type. It is used by the function template to + * accept NULL pointers. + * @endif + */ + struct _M_clear_type; + + /** + * @if maint + * Trait identifying "location-invariant" types, meaning that the + * address of the object (or any of its members) will not escape. + * Also implies a trivial copy constructor and assignment operator. + * @endif + */ + template + struct __is_location_invariant + : integral_constant::value + || is_member_pointer<_Tp>::value)> + { + }; + + class _Undefined_class; + + union _Nocopy_types + { + void* _M_object; + const void* _M_const_object; + void (*_M_function_pointer)(); + void (_Undefined_class::*_M_member_pointer)(); + }; + + union _Any_data { + void* _M_access() { return &_M_pod_data[0]; } + const void* _M_access() const { return &_M_pod_data[0]; } + + template _Tp& _M_access() + { return *static_cast<_Tp*>(_M_access()); } + + template const _Tp& _M_access() const + { return *static_cast(_M_access()); } + + _Nocopy_types _M_unused; + char _M_pod_data[sizeof(_Nocopy_types)]; + }; + + enum _Manager_operation + { + __get_type_info, + __get_functor_ptr, + __clone_functor, + __destroy_functor + }; + + /* Simple type wrapper that helps avoid annoying const problems + when casting between void pointers and pointers-to-pointers. */ + template + struct _Simple_type_wrapper + { + _Simple_type_wrapper(_Tp __value) : __value(__value) { } + + _Tp __value; + }; + + template + struct __is_location_invariant<_Simple_type_wrapper<_Tp> > + : __is_location_invariant<_Tp> + { + }; + + // Converts a reference to a function object into a callable + // function object. + template + inline _Functor& __callable_functor(_Functor& __f) { return __f; } + + template + inline _Mem_fn<_Member _Class::*> + __callable_functor(_Member _Class::* &__p) + { return mem_fn(__p); } + + template + inline _Mem_fn<_Member _Class::*> + __callable_functor(_Member _Class::* const &__p) + { return mem_fn(__p); } + + template + class _Function_handler; + + template + class function; + + + /** + * @if maint + * Base class of all polymorphic function object wrappers. + * @endif + */ + class _Function_base + { + public: + static const std::size_t _M_max_size = sizeof(_Nocopy_types); + static const std::size_t _M_max_align = __alignof__(_Nocopy_types); + + template + class _Base_manager + { + protected: + static const bool __stored_locally = + (__is_location_invariant<_Functor>::value + && sizeof(_Functor) <= _M_max_size + && __alignof__(_Functor) <= _M_max_align + && (_M_max_align % __alignof__(_Functor) == 0)); + typedef integral_constant _Local_storage; + + // Retrieve a pointer to the function object + static _Functor* _M_get_pointer(const _Any_data& __source) + { + const _Functor* __ptr = + __stored_locally? &__source._M_access<_Functor>() + /* have stored a pointer */ : __source._M_access<_Functor*>(); + return const_cast<_Functor*>(__ptr); + } + + // Clone a location-invariant function object that fits within + // an _Any_data structure. + static void + _M_clone(_Any_data& __dest, const _Any_data& __source, true_type) + { + new (__dest._M_access()) _Functor(__source._M_access<_Functor>()); + } + + // Clone a function object that is not location-invariant or + // that cannot fit into an _Any_data structure. + static void + _M_clone(_Any_data& __dest, const _Any_data& __source, false_type) + { + __dest._M_access<_Functor*>() = + new _Functor(*__source._M_access<_Functor*>()); + } + + // Destroying a location-invariant object may still require + // destruction. + static void + _M_destroy(_Any_data& __victim, true_type) + { + __victim._M_access<_Functor>().~_Functor(); + } + + // Destroying an object located on the heap. + static void + _M_destroy(_Any_data& __victim, false_type) + { + delete __victim._M_access<_Functor*>(); + } + + public: + static bool + _M_manager(_Any_data& __dest, const _Any_data& __source, + _Manager_operation __op) + { + switch (__op) { + case __get_type_info: + __dest._M_access() = &typeid(_Functor); + break; + + case __get_functor_ptr: + __dest._M_access<_Functor*>() = _M_get_pointer(__source); + break; + + case __clone_functor: + _M_clone(__dest, __source, _Local_storage()); + break; + + case __destroy_functor: + _M_destroy(__dest, _Local_storage()); + break; + } + return false; + } + + static void + _M_init_functor(_Any_data& __functor, const _Functor& __f) + { + _M_init_functor(__functor, __f, _Local_storage()); + } + + template + static bool + _M_not_empty_function(const function<_Signature>& __f) + { + return __f; + } + + template + static bool + _M_not_empty_function(const _Tp*& __fp) + { + return __fp; + } + + template + static bool + _M_not_empty_function(_Tp _Class::* const& __mp) + { + return __mp; + } + + template + static bool + _M_not_empty_function(const _Tp&) + { + return true; + } + + private: + static void + _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type) + { + new (__functor._M_access()) _Functor(__f); + } + + static void + _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type) + { + __functor._M_access<_Functor*>() = new _Functor(__f); + } + }; + + template + class _Ref_manager : public _Base_manager<_Functor*> + { + typedef _Function_base::_Base_manager<_Functor*> _Base; + + public: + static bool + _M_manager(_Any_data& __dest, const _Any_data& __source, + _Manager_operation __op) + { + switch (__op) { + case __get_type_info: + __dest._M_access() = &typeid(_Functor); + break; + + case __get_functor_ptr: + __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source); + return is_const<_Functor>::value; + break; + + default: + _Base::_M_manager(__dest, __source, __op); + } + return false; + } + + static void + _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f) + { + // TBD: Use address_of function instead + _Base::_M_init_functor(__functor, &__f.get()); + } + }; + + _Function_base() : _M_manager(0) { } + + ~_Function_base() + { + if (_M_manager) + { + _M_manager(_M_functor, _M_functor, __destroy_functor); + } + } + + + bool _M_empty() const { return !_M_manager; } + + typedef bool (*_Manager_type)(_Any_data&, const _Any_data&, + _Manager_operation); + + _Any_data _M_functor; + _Manager_type _M_manager; + }; + +#define _GLIBCXX_NUM_ARGS 0 +#define _GLIBCXX_COMMA +#define _GLIBCXX_TEMPLATE_PARAMS +#define _GLIBCXX_TEMPLATE_ARGS +#define _GLIBCXX_PARAMS +#define _GLIBCXX_ARGS +#define _GLIBCXX_COMMA_SHIFTED +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#define _GLIBCXX_PARAMS_SHIFTED +#define _GLIBCXX_ARGS_SHIFTED +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 1 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1 +#define _GLIBCXX_TEMPLATE_ARGS _T1 +#define _GLIBCXX_PARAMS _T1 __a1 +#define _GLIBCXX_ARGS __a1 +#define _GLIBCXX_COMMA_SHIFTED +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#define _GLIBCXX_PARAMS_SHIFTED +#define _GLIBCXX_ARGS_SHIFTED +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 2 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2 +#define _GLIBCXX_ARGS __a1, __a2 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1 +#define _GLIBCXX_ARGS_SHIFTED __a1 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 3 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3 +#define _GLIBCXX_ARGS __a1, __a2, __a3 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 4 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 5 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 6 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 7 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 8 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 9 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 10 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 11 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 12 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 13 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 14 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 15 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 16 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 17 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16, typename _T17 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16, _T17 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16, _T17 __a17 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16, __a17 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 18 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16, typename _T17, typename _T18 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16, _T17, _T18 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16, _T17 __a17, _T18 __a18 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16, __a17, __a18 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16, typename _T17 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16, _T17 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16, _T17 __a17 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16, __a17 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 19 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16, typename _T17, typename _T18, typename _T19 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16, _T17, _T18, _T19 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16, _T17 __a17, _T18 __a18, _T19 __a19 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16, __a17, __a18, __a19 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16, typename _T17, typename _T18 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16, _T17, _T18 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16, _T17 __a17, _T18 __a18 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16, __a17, __a18 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + +#define _GLIBCXX_NUM_ARGS 20 +#define _GLIBCXX_COMMA , +#define _GLIBCXX_TEMPLATE_PARAMS typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16, typename _T17, typename _T18, typename _T19, typename _T20 +#define _GLIBCXX_TEMPLATE_ARGS _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16, _T17, _T18, _T19, _T20 +#define _GLIBCXX_PARAMS _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16, _T17 __a17, _T18 __a18, _T19 __a19, _T20 __a20 +#define _GLIBCXX_ARGS __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16, __a17, __a18, __a19, __a20 +#define _GLIBCXX_COMMA_SHIFTED , +#define _GLIBCXX_TEMPLATE_PARAMS_SHIFTED typename _T1, typename _T2, typename _T3, typename _T4, typename _T5, typename _T6, typename _T7, typename _T8, typename _T9, typename _T10, typename _T11, typename _T12, typename _T13, typename _T14, typename _T15, typename _T16, typename _T17, typename _T18, typename _T19 +#define _GLIBCXX_TEMPLATE_ARGS_SHIFTED _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10, _T11, _T12, _T13, _T14, _T15, _T16, _T17, _T18, _T19 +#define _GLIBCXX_PARAMS_SHIFTED _T1 __a1, _T2 __a2, _T3 __a3, _T4 __a4, _T5 __a5, _T6 __a6, _T7 __a7, _T8 __a8, _T9 __a9, _T10 __a10, _T11 __a11, _T12 __a12, _T13 __a13, _T14 __a14, _T15 __a15, _T16 __a16, _T17 __a17, _T18 __a18, _T19 __a19 +#define _GLIBCXX_ARGS_SHIFTED __a1, __a2, __a3, __a4, __a5, __a6, __a7, __a8, __a9, __a10, __a11, __a12, __a13, __a14, __a15, __a16, __a17, __a18, __a19 +#include +#undef _GLIBCXX_ARGS_SHIFTED +#undef _GLIBCXX_PARAMS_SHIFTED +#undef _GLIBCXX_TEMPLATE_ARGS_SHIFTED +#undef _GLIBCXX_TEMPLATE_PARAMS_SHIFTED +#undef _GLIBCXX_COMMA_SHIFTED +#undef _GLIBCXX_ARGS +#undef _GLIBCXX_PARAMS +#undef _GLIBCXX_TEMPLATE_ARGS +#undef _GLIBCXX_TEMPLATE_PARAMS +#undef _GLIBCXX_COMMA +#undef _GLIBCXX_NUM_ARGS + + // [3.7.2.7] null pointer comparisons + + /** + * @brief Compares a polymorphic function object wrapper against 0 + * (the NULL pointer). + * @returns @c true if the wrapper has no target, @c false otherwise + * + * This function will not throw an exception. + */ + template + inline bool + operator==(const function<_Signature>& __f, _M_clear_type*) + { + return !__f; + } + + /** + * @overload + */ + template + inline bool + operator==(_M_clear_type*, const function<_Signature>& __f) + { + return !__f; + } + + /** + * @brief Compares a polymorphic function object wrapper against 0 + * (the NULL pointer). + * @returns @c false if the wrapper has no target, @c true otherwise + * + * This function will not throw an exception. + */ + template + inline bool + operator!=(const function<_Signature>& __f, _M_clear_type*) + { + return __f; + } + + /** + * @overload + */ + template + inline bool + operator!=(_M_clear_type*, const function<_Signature>& __f) + { + return __f; + } + + // [3.7.2.8] specialized algorithms + + /** + * @brief Swap the targets of two polymorphic function object wrappers. + * + * This function will not throw an exception. + */ + template + inline void + swap(function<_Signature>& __x, function<_Signature>& __y) + { + __x.swap(__y); + } + // Definition of default hash function std::tr1::hash<>. The types for // which std::tr1::hash is defined is in clause 6.3.3. of the PDTR. template struct hash; - #define tr1_hashtable_define_trivial_hash(T) \ - template <> struct hash { \ + #define tr1_hashtable_define_trivial_hash(T) \ + template <> struct hash { \ std::size_t operator()(T val) const { return static_cast(val); } \ - } \ + } \ tr1_hashtable_define_trivial_hash(bool); tr1_hashtable_define_trivial_hash(char); @@ -121,7 +1089,7 @@ namespace tr1 template struct hash { std::size_t operator()(T* p) const { - return reinterpret_cast(p); + return reinterpret_cast(p); } }; @@ -137,10 +1105,10 @@ namespace tr1 { std::size_t operator()(const std::string& s) const { - std::size_t result = 0; - for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) - result = (result * 131) + *i; - return result; + std::size_t result = 0; + for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) + result = (result * 131) + *i; + return result; } }; @@ -150,10 +1118,10 @@ namespace tr1 { std::size_t operator()(const std::wstring& s) const { - std::size_t result = 0; - for (std::wstring::const_iterator i = s.begin(); i != s.end(); ++i) - result = (result * 131) + *i; - return result; + std::size_t result = 0; + for (std::wstring::const_iterator i = s.begin(); i != s.end(); ++i) + result = (result * 131) + *i; + return result; } }; #endif diff --git a/libstdc++-v3/include/tr1/functional_iterate.h b/libstdc++-v3/include/tr1/functional_iterate.h new file mode 100644 index 00000000000..8f94d8ecdc9 --- /dev/null +++ b/libstdc++-v3/include/tr1/functional_iterate.h @@ -0,0 +1,700 @@ +// TR1 functional -*- C++ -*- + +// Copyright (C) 2005 Free Software Foundation, Inc. +// Writtten by Douglas Gregor +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file function_iterate.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_NUM_ARGS > 0 +template + class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED)> +#if _GLIBCXX_NUM_ARGS == 1 + : public unary_function<_Class*, _Res> +#elif _GLIBCXX_NUM_ARGS == 2 + : public binary_function<_Class*, _T1, _Res> +#endif + { + typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED); + + template + _Res + _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(_Class& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle pointers + _Res + operator()(_Class* __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle smart pointers, references and pointers to derived + template + _Res + operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { + return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_ARGS_SHIFTED); + } + + private: + _Functor __pmf; + }; + +template + class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const> +#if _GLIBCXX_NUM_ARGS == 1 + : public unary_function +#elif _GLIBCXX_NUM_ARGS == 2 + : public binary_function +#endif + { + typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const; + + template + _Res + _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(const _Class& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle pointers + _Res + operator()(const _Class* __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle smart pointers, references and pointers to derived + template + _Res + operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { + return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_ARGS_SHIFTED); + } + + private: + _Functor __pmf; + }; + +template + class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile> +#if _GLIBCXX_NUM_ARGS == 1 + : public unary_function +#elif _GLIBCXX_NUM_ARGS == 2 + : public binary_function +#endif + { + typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile; + + template + _Res + _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(volatile _Class& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle pointers + _Res + operator()(volatile _Class* __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle smart pointers, references and pointers to derived + template + _Res + operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { + return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_ARGS_SHIFTED); + } + private: + _Functor __pmf; + }; + +template + class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const volatile> +#if _GLIBCXX_NUM_ARGS == 1 + : public unary_function +#elif _GLIBCXX_NUM_ARGS == 2 + : public binary_function +#endif + { + typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) + const volatile; + + template + _Res + _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(const volatile _Class& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle pointers + _Res + operator()(const volatile _Class* __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); } + + // Handle smart pointers, references and pointers to derived + template + _Res + operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_PARAMS_SHIFTED) const + { + return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED + _GLIBCXX_ARGS_SHIFTED); + } + + private: + _Functor __pmf; + }; +#endif + +template class _Function_handler; + +template +class _Function_handler<_Res(_GLIBCXX_TEMPLATE_ARGS), _Functor> + : public _Function_base::_Base_manager<_Functor> +{ + typedef _Function_base::_Base_manager<_Functor> _Base; + + public: + static _Res + _M_invoke(const _Any_data& __functor _GLIBCXX_COMMA _GLIBCXX_PARAMS) + { + return (*_Base::_M_get_pointer(__functor))(_GLIBCXX_ARGS); + } +}; + +template +class _Function_handler + : public _Function_base::_Base_manager<_Functor> +{ + typedef _Function_base::_Base_manager<_Functor> _Base; + + public: + static void + _M_invoke(const _Any_data& __functor _GLIBCXX_COMMA _GLIBCXX_PARAMS) + { + (*_Base::_M_get_pointer(__functor))(_GLIBCXX_ARGS); + } +}; + +template +class _Function_handler<_Res(_GLIBCXX_TEMPLATE_ARGS), + reference_wrapper<_Functor> > + : public _Function_base::_Ref_manager<_Functor> +{ + typedef _Function_base::_Ref_manager<_Functor> _Base; + + public: + static _Res + _M_invoke(const _Any_data& __functor _GLIBCXX_COMMA _GLIBCXX_PARAMS) + { + return __callable_functor(**_Base::_M_get_pointer(__functor)) + (_GLIBCXX_ARGS); + } +}; + +template +class _Function_handler > + : public _Function_base::_Ref_manager<_Functor> +{ + typedef _Function_base::_Ref_manager<_Functor> _Base; + + public: + static void + _M_invoke(const _Any_data& __functor _GLIBCXX_COMMA _GLIBCXX_PARAMS) + { + __callable_functor(**_Base::_M_get_pointer(__functor))(_GLIBCXX_ARGS); + } +}; + +template +class _Function_handler<_Res(_GLIBCXX_TEMPLATE_ARGS), _Member _Class::*> + : public _Function_handler +{ + typedef _Function_handler + _Base; + + public: + static _Res + _M_invoke(const _Any_data& __functor _GLIBCXX_COMMA _GLIBCXX_PARAMS) + { + return std::tr1::mem_fn(_Base::_M_get_pointer(__functor)->__value) + (_GLIBCXX_ARGS); + } +}; + +template +class _Function_handler + : public _Function_base::_Base_manager< + _Simple_type_wrapper< _Member _Class::* > > +{ + typedef _Member _Class::* _Functor; + typedef _Simple_type_wrapper< _Functor > _Wrapper; + typedef _Function_base::_Base_manager<_Wrapper> _Base; + + public: + static bool + _M_manager(_Any_data& __dest, const _Any_data& __source, + _Manager_operation __op) + { + switch (__op) { + case __get_type_info: + __dest._M_access() = &typeid(_Functor); + break; + + case __get_functor_ptr: + __dest._M_access<_Functor*>() = + &_Base::_M_get_pointer(__source)->__value; + break; + + default: + _Base::_M_manager(__dest, __source, __op); + } + return false; + } + + static void + _M_invoke(const _Any_data& __functor _GLIBCXX_COMMA _GLIBCXX_PARAMS) + { + std::tr1::mem_fn(_Base::_M_get_pointer(__functor)->__value) + (_GLIBCXX_ARGS); + } +}; + +template +class function<_Res(_GLIBCXX_TEMPLATE_ARGS)> +#if _GLIBCXX_NUM_ARGS == 1 + : public unary_function<_T1, _Res>, private _Function_base +#elif _GLIBCXX_NUM_ARGS == 2 + : public binary_function<_T1, _T2, _Res>, private _Function_base +#else + : private _Function_base +#endif +{ + /** + * @if maint + * This class is used to implement the safe_bool idiom. + * @endif + */ + struct _Hidden_type + { + _Hidden_type* _M_bool; + }; + + /** + * @if maint + * This typedef is used to implement the safe_bool idiom. + * @endif + */ + typedef _Hidden_type* _Hidden_type::* _Safe_bool; + + typedef _Res _Signature_type(_GLIBCXX_TEMPLATE_ARGS); + + struct _Useless {}; + + public: + typedef _Res result_type; + + // [3.7.2.1] construct/copy/destroy + + /** + * @brief Default construct creates an empty function call wrapper. + * @post @c !(bool)*this + */ + function() : _Function_base() { } + + /** + * @brief Default construct creates an empty function call wrapper. + * @post @c !(bool)*this + */ + function(_M_clear_type*) : _Function_base() { } + + /** + * @brief %Function copy constructor. + * @param x A %function object with identical call signature. + * @pre @c (bool)*this == (bool)x + * + * The newly-created %function contains a copy of the target of @a + * x (if it has one). + */ + function(const function& __x); + + /** + * @brief Builds a %function that targets a copy of the incoming + * function object. + * @param f A %function object that is callable with parameters of + * type @c T1, @c T2, ..., @c TN and returns a value convertible + * to @c Res. + * + * The newly-created %function object will target a copy of @a + * f. If @a f is @c reference_wrapper, then this function + * object will contain a reference to the function object @c + * f.get(). If @a f is a NULL function pointer or NULL + * pointer-to-member, the newly-created object will be empty. + * + * If @a f is a non-NULL function pointer or an object of type @c + * reference_wrapper, this function will not throw. + */ + template + function(_Functor __f, + typename __enable_if<_Useless, + !is_integral<_Functor>::value>::__type + = _Useless()); + + /** + * @brief %Function assignment operator. + * @param x A %function with identical call signature. + * @post @c (bool)*this == (bool)x + * @returns @c *this + * + * The target of @a x is copied to @c *this. If @a x has no + * target, then @c *this will be empty. + * + * If @a x targets a function pointer or a reference to a function + * object, then this operation will not throw an exception. + */ + function& operator=(const function& __x) + { + function(__x).swap(*this); + return *this; + } + + /** + * @brief %Function assignment to zero. + * @post @c !(bool)*this + * @returns @c *this + * + * The target of @a *this is deallocated, leaving it empty. + */ + function& operator=(_M_clear_type*) + { + if (_M_manager) { + _M_manager(_M_functor, _M_functor, __destroy_functor); + _M_manager = 0; + _M_invoker = 0; + } + return *this; + } + + /** + * @brief %Function assignment to a new target. + * @param f A %function object that is callable with parameters of + * type @c T1, @c T2, ..., @c TN and returns a value convertible + * to @c Res. + * @return @c *this + * + * This %function object wrapper will target a copy of @a + * f. If @a f is @c reference_wrapper, then this function + * object will contain a reference to the function object @c + * f.get(). If @a f is a NULL function pointer or NULL + * pointer-to-member, @c this object will be empty. + * + * If @a f is a non-NULL function pointer or an object of type @c + * reference_wrapper, this function will not throw. + */ + template + typename __enable_if::value>::__type + operator=(_Functor __f) + { + function(__f).swap(*this); + return *this; + } + + // [3.7.2.2] function modifiers + + /** + * @brief Swap the targets of two %function objects. + * @param f A %function with identical call signature. + * + * Swap the targets of @c this function object and @a f. This + * function will not throw an exception. + */ + void swap(function& __x) + { + _Any_data __old_functor = _M_functor; + _M_functor = __x._M_functor; + __x._M_functor = __old_functor; + _Manager_type __old_manager = _M_manager; + _M_manager = __x._M_manager; + __x._M_manager = __old_manager; + _Invoker_type __old_invoker = _M_invoker; + _M_invoker = __x._M_invoker; + __x._M_invoker = __old_invoker; + } + + // [3.7.2.3] function capacity + + /** + * @brief Determine if the %function wrapper has a target. + * + * @return @c true when this %function object contains a target, + * or @c false when it is empty. + * + * This function will not throw an exception. + */ + operator _Safe_bool() const + { + if (_M_empty()) + { + return 0; + } + else + { + return &_Hidden_type::_M_bool; + } + } + + // [3.7.2.4] function invocation + + /** + * @brief Invokes the function targeted by @c *this. + * @returns the result of the target. + * @throws bad_function_call when @c !(bool)*this + * + * The function call operator invokes the target function object + * stored by @c this. + */ + _Res operator()(_GLIBCXX_PARAMS) const; + + // [3.7.2.5] function target access + /** + * @brief Determine the type of the target of this function object + * wrapper. + * + * @returns the type identifier of the target function object, or + * @c typeid(void) if @c !(bool)*this. + * + * This function will not throw an exception. + */ + const type_info& target_type() const; + + /** + * @brief Access the stored target function object. + * + * @return Returns a pointer to the stored target function object, + * if @c typeid(Functor).equals(target_type()); otherwise, a NULL + * pointer. + * + * This function will not throw an exception. + */ + template _Functor* target(); + + /** + * @overload + */ + template const _Functor* target() const; + + private: + // [3.7.2.6] undefined operators + template + void operator==(const function<_Function>&) const; + template + void operator!=(const function<_Function>&) const; + + typedef _Res (*_Invoker_type)(const _Any_data& _GLIBCXX_COMMA _GLIBCXX_PARAMS); + _Invoker_type _M_invoker; +}; + +template + function<_Res(_GLIBCXX_TEMPLATE_ARGS)>::function(const function& __x) + : _Function_base() + { + if (__x) { + _M_invoker = __x._M_invoker; + _M_manager = __x._M_manager; + __x._M_manager(_M_functor, __x._M_functor, __clone_functor); + } + } + +template +template + function<_Res(_GLIBCXX_TEMPLATE_ARGS)> + ::function(_Functor __f, + typename __enable_if<_Useless, + !is_integral<_Functor>::value>::__type) + : _Function_base() +{ + typedef _Function_handler<_Signature_type, _Functor> _My_handler; + if (_My_handler::_M_not_empty_function(__f)) { + _M_invoker = &_My_handler::_M_invoke; + _M_manager = &_My_handler::_M_manager; + _My_handler::_M_init_functor(_M_functor, __f); + } +} + +template + _Res function<_Res(_GLIBCXX_TEMPLATE_ARGS)>::operator()(_GLIBCXX_PARAMS) const + { + if (_M_empty()) + { +#if __EXCEPTIONS + throw bad_function_call(); +#else + std::abort(); +#endif + } + return _M_invoker(_M_functor _GLIBCXX_COMMA _GLIBCXX_ARGS); + } + +template + const type_info& + function<_Res(_GLIBCXX_TEMPLATE_ARGS)>::target_type() const + { + if (_M_manager) + { + _Any_data __typeinfo_result; + _M_manager(__typeinfo_result, _M_functor, __get_type_info); + return *__typeinfo_result._M_access(); + } + else + { + return typeid(void); + } + } + +template +template + _Functor* + function<_Res(_GLIBCXX_TEMPLATE_ARGS)>::target() + { + if (typeid(_Functor) == target_type() && _M_manager) + { + _Any_data __ptr; + if (_M_manager(__ptr, _M_functor, __get_functor_ptr) + && !is_const<_Functor>::value) + return 0; + else + return __ptr._M_access<_Functor*>(); + } + else + { + return 0; + } + } + +template +template + const _Functor* + function<_Res(_GLIBCXX_TEMPLATE_ARGS)>::target() const + { + if (typeid(_Functor) == target_type() && _M_manager) + { + _Any_data __ptr; + _M_manager(__ptr, _M_functor, __get_functor_ptr); + return __ptr._M_access(); + } + else + { + return 0; + } + } + diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index a0302c13653..2a47483951c 100644 --- a/libstdc++-v3/testsuite/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/testsuite_tr1.h @@ -32,10 +32,10 @@ #define _GLIBCXX_TESTSUITE_TR1_H namespace __gnu_test -{ +{ // For tr1/type_traits. template class Category, - typename Type> + typename Type> bool test_category(bool value) { @@ -52,7 +52,7 @@ namespace __gnu_test } template class Property, - typename Type> + typename Type> bool test_property(typename Property::value_type value) { @@ -63,7 +63,7 @@ namespace __gnu_test } template class Property, - typename Type> + typename Type> bool test_copy_property(bool value) { @@ -80,7 +80,7 @@ namespace __gnu_test } template class Property, - typename Type> + typename Type> bool test_assign_property(bool value) { @@ -97,7 +97,7 @@ namespace __gnu_test } template class Relationship, - typename Type1, typename Type2> + typename Type1, typename Type2> bool test_relationship(bool value) { @@ -122,7 +122,68 @@ namespace __gnu_test class AbstractClass { virtual void rotate(int) = 0; }; - + + + int truncate_float(float x) { return (int)x; } + long truncate_double(double x) { return (long)x; } + + struct do_truncate_float_t + { + do_truncate_float_t() + { + ++live_objects; + } + + do_truncate_float_t(const do_truncate_float_t&) + { + ++live_objects; + } + + ~do_truncate_float_t() + { + --live_objects; + } + + int operator()(float x) { return (int)x; } + + static int live_objects; + }; + + int do_truncate_float_t::live_objects = 0; + + struct do_truncate_double_t + { + do_truncate_double_t() + { + ++live_objects; + } + + do_truncate_double_t(const do_truncate_double_t&) + { + ++live_objects; + } + + ~do_truncate_double_t() + { + --live_objects; + } + + long operator()(double x) { return (long)x; } + + static int live_objects; + }; + + int do_truncate_double_t::live_objects = 0; + + struct X + { + int bar; + + int foo() { return 1; } + int foo_c() const { return 2; } + int foo_v() volatile { return 3; } + int foo_cv() const volatile { return 4; } + }; }; // namespace __gnu_test #endif // _GLIBCXX_TESTSUITE_TR1_H diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc new file mode 100644 index 00000000000..5d368e4edcc --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc @@ -0,0 +1,95 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Operations on empty function<> objects +void test01() +{ + using std::tr1::function; + using std::tr1::bad_function_call; + + // Default-construction + function f1; + VERIFY( ((bool)f1 == false) ); + VERIFY( !f1 ); + VERIFY( f1 == 0 ); + VERIFY( 0 == f1 ); + VERIFY( !(f1 != 0) ); + VERIFY( !(0 != f1) ); + + // Copy-construction + function f2(f1); + VERIFY( !f2 ); + + // Construct with NULL pointer + function f3(0); + VERIFY( !f3 ); + + // Assignment + f1 = f2; + VERIFY( !f1); + + // Assignment to NULL pointer + f1 = 0; + VERIFY( !f1 ); + + // Swap + swap(f1, f2); + VERIFY( !f1 ); + VERIFY( !f2 ); + + // Invocation should throw bad_function_call + bool thrown = false; + try + { + f1(3.14159f); + VERIFY( false ); + } + catch (bad_function_call) + { + thrown = true; + } + VERIFY( thrown ); + + // target_type returns typeid(void) + VERIFY( f1.target_type() == typeid(void) ); + + // target() always returns a NULL pointer + VERIFY( f1.target() == 0); + + // Check const version + const function& f1c = f1; + VERIFY( f1c.target() == 0 ); + VERIFY( !f1c ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc new file mode 100644 index 00000000000..86abaf0e5bf --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc @@ -0,0 +1,78 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put function pointers into function<> wrappers +void test02() +{ + using std::tr1::function; + + function f1(truncate_float); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Copy-construction + function f2(f1); + VERIFY( f2 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + VERIFY( f2(3.1f) == 3 ); + + // Assignment to zero + f1 = 0; + VERIFY( !f1 ); + + // Swap + f1.swap(f2); + VERIFY( f1 ); + VERIFY( !f2 ); + VERIFY( f1(3.1f) == 3 ); + + // Assignment from a function pointer + f2 = truncate_float; + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function& f1c = f1; + VERIFY( typeid(int(*)(float)) == f1.target_type() ); + VERIFY( f2.target() != 0 ); + VERIFY( *f2.target() == &truncate_float ); + VERIFY( f1c.target() != 0 ); + VERIFY( *f1c.target() == &truncate_float ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc new file mode 100644 index 00000000000..6812817070e --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc @@ -0,0 +1,78 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put nearly-matching function pointers into function<> wrappers +void test03() +{ + using std::tr1::function; + + function f1(truncate_double); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Copy-construction + function f2(f1); + VERIFY( f2 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + VERIFY( f2(3.1f) == 3 ); + + // Assignment to zero + f1 = 0; + VERIFY( !f1 ); + + // Swap + f1.swap(f2); + VERIFY( f1 ); + VERIFY( !f2 ); + VERIFY( f1(3.1f) == 3 ); + + // Assignment from a function pointer + f2 = truncate_double; + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function& f1c = f1; + VERIFY( typeid(long(*)(double)) == f1.target_type() ); + VERIFY( f2.target() != 0 ); + VERIFY( *f2.target() == &truncate_double ); + VERIFY( f1c.target() != 0 ); + VERIFY( *f1c.target() == &truncate_double ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc new file mode 100644 index 00000000000..a5150ca8dab --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc @@ -0,0 +1,82 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put function objects into function<> wrappers +void test04() +{ + using std::tr1::function; + + do_truncate_float_t truncate_float; + + function f1(truncate_float); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Copy-construction + function f2(f1); + VERIFY( f2 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + VERIFY( f2(3.1f) == 3 ); + + // Assignment to zero + f1 = 0; + VERIFY( !f1 ); + + // Swap + f1.swap(f2); + VERIFY( f1 ); + VERIFY( !f2 ); + VERIFY( f1(3.1f) == 3 ); + + // Assignment from a function pointer + f2 = do_truncate_float_t(); + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function& f1c = f1; + VERIFY( typeid(do_truncate_float_t) == f1.target_type() ); + VERIFY( f2.target() != 0 ); + VERIFY( f1c.target() != 0 ); +} + +int main() +{ + test04(); + + VERIFY( do_truncate_double_t::live_objects == 0 ); + VERIFY( do_truncate_float_t::live_objects == 0 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc new file mode 100644 index 00000000000..16d552edd84 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc @@ -0,0 +1,107 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put member pointers into function<> wrappers +void test05() +{ + using std::tr1::function; + + X x; + x.bar = 17; + + function frm(&X::bar); + VERIFY( frm ); + VERIFY( frm(x) == 17 ); + VERIFY( typeid(int X::*) == frm.target_type() ); + VERIFY( *frm.target() == &X::bar ); + + function fr(&X::foo); + VERIFY( fr ); + VERIFY( fr(x) == 1 ); + VERIFY( typeid(int (X::*)()) == fr.target_type() ); + VERIFY( *fr.target() == &X::foo ); + + function frc(&X::foo_c); + VERIFY( frc ); + VERIFY( frc(x) == 2 ); + VERIFY( typeid(int (X::*)() const) == frc.target_type() ); + VERIFY( *frc.target() == &X::foo_c ); + + function frv(&X::foo_v); + VERIFY( frv ); + VERIFY( frv(x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); + VERIFY( *frv.target() == &X::foo_v ); + VERIFY( frv.target() == 0 ); + + function frcv(&X::foo_cv); + VERIFY( frcv ); + VERIFY( frcv(x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); + VERIFY( *frcv.target() == &X::foo_cv ); + VERIFY( frcv.target() == 0 ); + + function grm(&X::bar); + VERIFY( grm ); + VERIFY( grm(&x) == 17 ); + VERIFY( typeid(int X::*) == grm.target_type() ); + VERIFY( *grm.target() == &X::bar ); + + function gr(&X::foo); + VERIFY( gr ); + VERIFY( gr(&x) == 1 ); + VERIFY( typeid(int (X::*)()) == gr.target_type() ); + VERIFY( *gr.target() == &X::foo ); + + function grc(&X::foo_c); + VERIFY( grc ); + VERIFY( grc(&x) == 2 ); + VERIFY( typeid(int (X::*)() const) == grc.target_type() ); + VERIFY( *grc.target() == &X::foo_c ); + + function grv(&X::foo_v); + VERIFY( grv ); + VERIFY( grv(&x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); + VERIFY( *grv.target() == &X::foo_v ); + VERIFY( grv.target() == 0 ); + + function grcv(&X::foo_cv); + VERIFY( grcv ); + VERIFY( grcv(&x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); + VERIFY( *grcv.target() == &X::foo_cv ); + VERIFY( grcv.target() == 0 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc new file mode 100644 index 00000000000..50bb854a6cd --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc @@ -0,0 +1,83 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +struct secret {}; + +struct noncopyable_function_object_type +{ + noncopyable_function_object_type(secret) {} + + int operator()() const { return 42; } + int operator()() { return 17; } + + private: + noncopyable_function_object_type(); + noncopyable_function_object_type(const noncopyable_function_object_type&); + void operator=(const noncopyable_function_object_type&); +}; + +// Put reference_wrappers into function<> wrappers +void test06() +{ + using std::tr1::function; + using std::tr1::ref; + using std::tr1::cref; + + secret password; + noncopyable_function_object_type x(password); + + function f(ref(x)); + VERIFY( f ); + VERIFY( f() == 17 ); + VERIFY( f.target_type() == typeid(noncopyable_function_object_type) ); + VERIFY( f.target() == &x ); + + function g = f; + VERIFY( g ); + VERIFY( g() == 17 ); + VERIFY( g.target_type() == typeid(noncopyable_function_object_type) ); + VERIFY( g.target() == &x ); + + function h = cref(x); + VERIFY( h ); + VERIFY( h() == 42 ); + VERIFY( h.target_type() == typeid(noncopyable_function_object_type) ); + VERIFY( h.target() == &x ); + VERIFY( h.target() == &x ); + + const function& hc = h; + VERIFY( h.target() == 0 ); + VERIFY( hc.target() == &x ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc new file mode 100644 index 00000000000..1a28f39f022 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc @@ -0,0 +1,82 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put reference_wrappers to function pointers into function<> wrappers +void test07() +{ + using std::tr1::function; + using std::tr1::ref; + using std::tr1::cref; + + int (*fptr)(float) = truncate_float; + + function f1(ref(fptr)); + VERIFY( f1 ); + VERIFY( !!f1 ); + VERIFY( !(f1 == 0) ); + VERIFY( !(0 == f1) ); + VERIFY( f1 != 0 ); + VERIFY( 0 != f1 ); + + // Invocation + VERIFY( f1(3.1f) == 3 ); + + // target_type and target() functions + const function& f1c = f1; + VERIFY( typeid(int(*)(float)) == f1.target_type() ); + VERIFY( f1.target() != 0 ); + VERIFY( f1.target() == &fptr ); + VERIFY( f1c.target() != 0 ); + VERIFY( f1c.target() == &fptr ); + + function f2(cref(fptr)); + VERIFY( f2 ); + VERIFY( !!f2 ); + VERIFY( !(f2 == 0) ); + VERIFY( !(0 == f2) ); + VERIFY( f2 != 0 ); + VERIFY( 0 != f2 ); + + // Invocation + VERIFY( f2(3.1f) == 3 ); + + // target_type and target() functions + const function& f2c = f2; + VERIFY( typeid(int(*)(float)) == f2.target_type() ); + VERIFY( f2.target() == 0 ); + VERIFY( f2.target() == &fptr ); + VERIFY( f2c.target() != 0 ); + VERIFY( f2c.target() == &fptr ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc new file mode 100644 index 00000000000..4253a2968c2 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc @@ -0,0 +1,148 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put reference_wrappers to member pointers +void test08() +{ + using std::tr1::function; + using std::tr1::ref; + using std::tr1::cref; + + int X::* X_bar = &X::bar; + int (X::* X_foo)() = &X::foo; + int (X::* X_foo_c)() const = &X::foo_c; + int (X::* X_foo_v)() volatile = &X::foo_v; + int (X::* X_foo_cv)() const volatile = &X::foo_cv; + + X x; + x.bar = 17; + + function frm(ref(X_bar)); + VERIFY( frm ); + VERIFY( frm(x) == 17 ); + VERIFY( typeid(int X::*) == frm.target_type() ); + VERIFY( frm.target() == &X_bar ); + + function fr(ref(X_foo)); + VERIFY( fr ); + VERIFY( fr(x) == 1 ); + VERIFY( typeid(int (X::*)()) == fr.target_type() ); + VERIFY( fr.target() == &X_foo ); + + function frc(ref(X_foo_c)); + VERIFY( frc ); + VERIFY( frc(x) == 2 ); + VERIFY( typeid(int (X::*)() const) == frc.target_type() ); + VERIFY( frc.target() == &X_foo_c ); + + function frv(ref(X_foo_v)); + VERIFY( frv ); + VERIFY( frv(x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); + VERIFY( *frv.target() == X_foo_v ); + VERIFY( frv.target() == 0 ); + + function frcv(ref(X_foo_cv)); + VERIFY( frcv ); + VERIFY( frcv(x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); + VERIFY( *frcv.target() == X_foo_cv ); + VERIFY( frcv.target() == 0 ); + + function grm(ref(X_bar)); + VERIFY( grm ); + VERIFY( grm(&x) == 17 ); + VERIFY( typeid(int X::*) == grm.target_type() ); + VERIFY( *grm.target() == X_bar ); + + function gr(ref(X_foo)); + VERIFY( gr ); + VERIFY( gr(&x) == 1 ); + VERIFY( typeid(int (X::*)()) == gr.target_type() ); + VERIFY( *gr.target() == X_foo ); + + function grc(ref(X_foo_c)); + VERIFY( grc ); + VERIFY( grc(&x) == 2 ); + VERIFY( typeid(int (X::*)() const) == grc.target_type() ); + VERIFY( *grc.target() == X_foo_c ); + + function grv(ref(X_foo_v)); + VERIFY( grv ); + VERIFY( grv(&x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); + VERIFY( *grv.target() == X_foo_v ); + VERIFY( grv.target() == 0 ); + + function grcv(ref(X_foo_cv)); + VERIFY( grcv ); + VERIFY( grcv(&x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); + VERIFY( *grcv.target() == X_foo_cv ); + VERIFY( grcv.target() == 0 ); + + function hrm(cref(X_bar)); + VERIFY( hrm ); + VERIFY( hrm(x) == 17 ); + VERIFY( typeid(int X::*) == hrm.target_type() ); + VERIFY( hrm.target() == 0 ); + VERIFY( hrm.target() == &X_bar ); + + function hr(cref(X_foo)); + VERIFY( hr ); + VERIFY( hr(x) == 1 ); + VERIFY( typeid(int (X::*)()) == hr.target_type() ); + VERIFY( hr.target() == &X_foo ); + + function hrc(cref(X_foo_c)); + VERIFY( hrc ); + VERIFY( hrc(x) == 2 ); + VERIFY( typeid(int (X::*)() const) == hrc.target_type() ); + VERIFY( hrc.target() == &X_foo_c ); + + function hrv(cref(X_foo_v)); + VERIFY( hrv ); + VERIFY( hrv(x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == hrv.target_type() ); + VERIFY( hrv.target() == &X_foo_v ); + VERIFY( hrv.target() == 0 ); + + function hrcv(cref(X_foo_cv)); + VERIFY( hrcv ); + VERIFY( hrcv(x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == hrcv.target_type() ); + VERIFY( hrcv.target() == &X_foo_cv ); + VERIFY( hrcv.target() == 0 ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/9.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/9.cc new file mode 100644 index 00000000000..02747b63b1c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/9.cc @@ -0,0 +1,55 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put function objects into a void-returning function<> wrapper +void test09() +{ + using std::tr1::function; + using std::tr1::ref; + using std::tr1::cref; + + int (X::*X_foo_c)() const = &X::foo_c; + function f(&X::bar); + f = &X::foo; + f = ref(X_foo_c); + f = cref(X_foo_c); + + function g = &truncate_float; + g = do_truncate_float_t(); +} + +int main() +{ + test09(); + + VERIFY( do_truncate_double_t::live_objects == 0 ); + VERIFY( do_truncate_float_t::live_objects == 0 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/mem_fn.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/mem_fn.cc new file mode 100644 index 00000000000..b11aa153af0 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/mem_fn.cc @@ -0,0 +1,78 @@ +// 2005-01-26 Douglas Gregor +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 3.5 function template mem_fn +#include +#include +#include + +struct X { int bar; }; + +struct Y : X { }; + +template +struct dumb_ptr +{ + dumb_ptr(T* p) : p(p) {} + + T& operator*() const { return *p; } + + private: + T* p; +}; + +// Test mem_fn with a data member +void test01() +{ + using std::tr1::mem_fn; + + X x; + Y y; + const X& xc = x; + const Y& yc = y; + X* xp = &x; + Y* yp =&y; + const X* xpc = xp; + const Y* ypc = yp; + dumb_ptr xd(xp); + dumb_ptr yd(yp); + const dumb_ptr& xdc = xd; + const dumb_ptr& ydc = yd; + + int& bx = mem_fn(&X::bar)(x); + const int& bxc = mem_fn(&X::bar)(xc); + int& bxp = mem_fn(&X::bar)(xp); + const int& bxpc = mem_fn(&X::bar)(xpc); + const int& bxd = mem_fn(&X::bar)(xd); + const int& bxdc = mem_fn(&X::bar)(xdc); + + int& by = mem_fn(&X::bar)(y); + const int& byc = mem_fn(&X::bar)(yc); + int& byp = mem_fn(&X::bar)(yp); + const int& bypc = mem_fn(&X::bar)(ypc); + const int& byd = mem_fn(&X::bar)(yd); + const int& bydc = mem_fn(&X::bar)(ydc); +} + +int main() +{ + test01(); + return 0; +}