⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functional

📁 Mac OS X 10.4.9 for x86 Source Code gcc 实现源代码
💻
📖 第 1 页 / 共 3 页
字号:
// TR1 functional header -*- C++ -*-// Copyright (C) 2004, 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.// 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 *  This is a TR1 C++ Library header. */#ifndef _TR1_FUNCTIONAL#define _TR1_FUNCTIONAL 1#include "../functional"#include <typeinfo>#include <tr1/type_traits>#include <bits/cpp_type_traits.h>#include <string>               // for std::tr1::hash#include <cstdlib>              // for std::abort#include <tr1/tuple>namespace std{namespace tr1{  template<typename _MemberPointer>    class _Mem_fn;  /**   *  @if maint   *  Actual implementation of _Has_result_type, which uses SFINAE to   *  determine if the type _Tp has a publicly-accessible member type   *  result_type.   *  @endif  */  template<typename _Tp>    class _Has_result_type_helper : __sfinae_types    {      template<typename _Up>      struct _Wrap_type      { };      template<typename _Up>        static __one __test(_Wrap_type<typename _Up::result_type>*);      template<typename _Up>        static __two __test(...);    public:      static const bool value = sizeof(__test<_Tp>(0)) == 1;    };  template<typename _Tp>    struct _Has_result_type       : integral_constant<           bool,           _Has_result_type_helper<typename remove_cv<_Tp>::type>::value>    { };  /**   *  @if maint   *  If we have found a result_type, extract it.   *  @endif  */  template<bool _Has_result_type, typename _Functor>    struct _Maybe_get_result_type    { };  template<typename _Functor>    struct _Maybe_get_result_type<true, _Functor>    {      typedef typename _Functor::result_type result_type;    };  /**   *  @if maint   *  Base class for any function object that has a weak result type, as   *  defined in 3.3/3 of TR1.   *  @endif  */  template<typename _Functor>    struct _Weak_result_type_impl      : _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor>    {    };  /**   *  @if maint   *  Strip top-level cv-qualifiers from the function object and let   *  _Weak_result_type_impl perform the real work.   *  @endif  */  template<typename _Functor>    struct _Weak_result_type    : _Weak_result_type_impl<typename remove_cv<_Functor>::type>    {    };  template<typename _Signature>    class result_of;  /**   *  @if maint   *  Actual implementation of result_of. When _Has_result_type is   *  true, gets its result from _Weak_result_type. Otherwise, uses   *  the function object's member template result to extract the   *  result type.   *  @endif  */  template<bool _Has_result_type, typename _Signature>    struct _Result_of_impl;  // Handle member data pointers using _Mem_fn's logic  template<typename _Res, typename _Class, typename _T1>    struct _Result_of_impl<false, _Res _Class::*(_T1)>    {      typedef typename _Mem_fn<_Res _Class::*>                ::template _Result_type<_T1>::type type;    };  /**   *  @if maint   *  Determines if the type _Tp derives from unary_function.   *  @endif  */  template<typename _Tp>    struct _Derives_from_unary_function : __sfinae_types    {    private:      template<typename _T1, typename _Res>        static __one __test(const volatile unary_function<_T1, _Res>*);      // It's tempting to change "..." to const volatile void*, but      // that fails when _Tp is a function type.      static __two __test(...);    public:      static const bool value = sizeof(__test((_Tp*)0)) == 1;    };  /**   *  @if maint   *  Determines if the type _Tp derives from binary_function.   *  @endif  */  template<typename _Tp>    struct _Derives_from_binary_function : __sfinae_types    {    private:      template<typename _T1, typename _T2, typename _Res>        static __one __test(const volatile binary_function<_T1, _T2, _Res>*);      // It's tempting to change "..." to const volatile void*, but      // that fails when _Tp is a function type.      static __two __test(...);    public:      static const bool value = sizeof(__test((_Tp*)0)) == 1;    };  /**   *  @if maint   *  Turns a function type into a function pointer type   *  @endif  */  template<typename _Tp, bool _IsFunctionType = is_function<_Tp>::value>    struct _Function_to_function_pointer    {      typedef _Tp type;    };  template<typename _Tp>    struct _Function_to_function_pointer<_Tp, true>    {      typedef _Tp* type;    };  /**   *  @if maint   *  Knowing which of unary_function and binary_function _Tp derives   *  from, derives from the same and ensures that reference_wrapper   *  will have a weak result type. See cases below.   *  @endif   */  template<bool _Unary, bool _Binary, typename _Tp>    struct _Reference_wrapper_base_impl;  // Not a unary_function or binary_function, so try a weak result type  template<typename _Tp>    struct _Reference_wrapper_base_impl<false, false, _Tp>      : _Weak_result_type<_Tp>    { };  // unary_function but not binary_function  template<typename _Tp>    struct _Reference_wrapper_base_impl<true, false, _Tp>      : unary_function<typename _Tp::argument_type,                       typename _Tp::result_type>    { };  // binary_function but not unary_function  template<typename _Tp>    struct _Reference_wrapper_base_impl<false, true, _Tp>      : binary_function<typename _Tp::first_argument_type,                        typename _Tp::second_argument_type,                        typename _Tp::result_type>    { };  // both unary_function and binary_function. import result_type to  // avoid conflicts.   template<typename _Tp>    struct _Reference_wrapper_base_impl<true, true, _Tp>      : unary_function<typename _Tp::argument_type,                       typename _Tp::result_type>,        binary_function<typename _Tp::first_argument_type,                        typename _Tp::second_argument_type,                        typename _Tp::result_type>    {      typedef typename _Tp::result_type result_type;    };  /**   *  @if maint   *  Derives from unary_function or binary_function when it   *  can. Specializations handle all of the easy cases. The primary   *  template determines what to do with a class type, which may   *  derive from both unary_function and binary_function.   *  @endif  */  template<typename _Tp>    struct _Reference_wrapper_base      : _Reference_wrapper_base_impl<          _Derives_from_unary_function<_Tp>::value,          _Derives_from_binary_function<_Tp>::value,          _Tp>    { };  // - a function type (unary)  template<typename _Res, typename _T1>    struct _Reference_wrapper_base<_Res(_T1)>      : unary_function<_T1, _Res>    { };  // - a function type (binary)  template<typename _Res, typename _T1, typename _T2>    struct _Reference_wrapper_base<_Res(_T1, _T2)>      : binary_function<_T1, _T2, _Res>    { };  // - a function pointer type (unary)  template<typename _Res, typename _T1>    struct _Reference_wrapper_base<_Res(*)(_T1)>      : unary_function<_T1, _Res>    { };  // - a function pointer type (binary)  template<typename _Res, typename _T1, typename _T2>    struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>      : binary_function<_T1, _T2, _Res>    { };  // - a pointer to member function type (unary, no qualifiers)  template<typename _Res, typename _T1>    struct _Reference_wrapper_base<_Res (_T1::*)()>      : unary_function<_T1*, _Res>    { };  // - a pointer to member function type (binary, no qualifiers)  template<typename _Res, typename _T1, typename _T2>    struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>      : binary_function<_T1*, _T2, _Res>    { };  // - a pointer to member function type (unary, const)  template<typename _Res, typename _T1>    struct _Reference_wrapper_base<_Res (_T1::*)() const>      : unary_function<const _T1*, _Res>    { };  // - a pointer to member function type (binary, const)  template<typename _Res, typename _T1, typename _T2>    struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>      : binary_function<const _T1*, _T2, _Res>    { };  // - a pointer to member function type (unary, volatile)  template<typename _Res, typename _T1>    struct _Reference_wrapper_base<_Res (_T1::*)() volatile>      : unary_function<volatile _T1*, _Res>    { };  // - a pointer to member function type (binary, volatile)  template<typename _Res, typename _T1, typename _T2>    struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>      : binary_function<volatile _T1*, _T2, _Res>    { };  // - a pointer to member function type (unary, const volatile)  template<typename _Res, typename _T1>    struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>      : unary_function<const volatile _T1*, _Res>    { };  // - a pointer to member function type (binary, const volatile)  template<typename _Res, typename _T1, typename _T2>    struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>      : binary_function<const volatile _T1*, _T2, _Res>    { };  template<typename _Tp>    class reference_wrapper      : public _Reference_wrapper_base<typename remove_cv<_Tp>::type>    {      // If _Tp is a function type, we can't form result_of<_Tp(...)>,      // so turn it into a function pointer type.      typedef typename _Function_to_function_pointer<_Tp>::type        _M_func_type;      _Tp* _M_data;    public:      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&      operator=(const reference_wrapper<_Tp>& __inref)      {        _M_data = __inref._M_data;        return *this;      }      operator _Tp&() const      { return this->get(); }      _Tp&      get() const      { return *_M_data; }#define _GLIBCXX_REPEAT_HEADER <tr1/ref_wrap_iterate.h>#include <tr1/repeat.h>#undef _GLIBCXX_REPEAT_HEADER    };  // Denotes a reference should be taken to a variable.  template<typename _Tp>    reference_wrapper<_Tp>    ref(_Tp& __t)    { return reference_wrapper<_Tp>(__t); }  // Denotes a const reference should be taken to a variable.  template<typename _Tp>    reference_wrapper<const _Tp>    cref(const _Tp& __t)    { return reference_wrapper<const _Tp>(__t); }  template<typename _Tp>    reference_wrapper<_Tp> ref(reference_wrapper<_Tp> __t)    { return ref(__t.get()); }  template<typename _Tp>    reference_wrapper<const _Tp> cref(reference_wrapper<_Tp> __t)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -