code:
// TR1 cwchar -*- C++ -*-

// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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 tr1/cwchar
 *  This is a TR1 C++ Library header.
 */

#ifndef _TR1_CWCHAR
#define _TR1_CWCHAR 1

#include <bits/c++config.h>

#if _GLIBCXX_USE_WCHAR_T

#include <cwchar>

// namespace std::tr1
namespace std
{
_GLIBCXX_BEGIN_NAMESPACE(tr1)

#if _GLIBCXX_HAVE_WCSTOF
  using std::wcstof;
#endif
#if _GLIBCXX_HAVE_VFWSCANF
  using std::vfwscanf;
#endif
#if _GLIBCXX_HAVE_VSWSCANF
  using std::vswscanf;
#endif
#if _GLIBCXX_HAVE_VWSCANF
  using std::vwscanf;
#endif

#if _GLIBCXX_USE_C99
  using std::wcstold;
  using std::wcstoll;
  using std::wcstoull;
#endif

_GLIBCXX_END_NAMESPACE
}

#endif

#endif


code:
// TR1 cwctype -*- C++ -*-

// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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 tr1/cwctype
 *  This is a TR1 C++ Library header.
 */

#ifndef _TR1_CWCTYPE
#define _TR1_CWCTYPE 1

#include <bits/c++config.h>

#if _GLIBCXX_USE_WCHAR_T

#include <cwctype>

// namespace std::tr1
namespace std
{
_GLIBCXX_BEGIN_NAMESPACE(tr1)

#if _GLIBCXX_HAVE_ISWBLANK
  using std::iswblank;
#endif

_GLIBCXX_END_NAMESPACE
}

#endif

#endif

repo_name: veiledmerc/mira

license: mit


code:
// TR1 fenv.h -*- C++ -*-

// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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 tr1/fenv.h
 *  This is a TR1 C++ Library header.
 */

#ifndef _TR1_FENV_H
#define _TR1_FENV_H 1

#include <tr1/cfenv>

#endif


code:
// TR1 float.h -*- C++ -*-

// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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 tr1/float.h
 *  This is a TR1 C++ Library header.
 */

#ifndef _TR1_FLOAT_H
#define _TR1_FLOAT_H 1

#include <tr1/cfloat>

#endif


code:
// TR1 functional header -*- C++ -*-

// Copyright (C) 2004, 2005, 2006, 2007 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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 tr1/functional
 *  This is a TR1 C++ Library header.
 */

#ifndef _TR1_FUNCTIONAL
#define _TR1_FUNCTIONAL 1

#pragma GCC system_header

#include "../functional"
#include <typeinfo>
#include <tr1/type_traits>
#include <ext/type_traits.h>
#include <cstdlib>  // for std::abort
#include <tr1/tuple>

namespace std
{
_GLIBCXX_BEGIN_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>
    inline reference_wrapper<_Tp>
    ref(_Tp& __t)
    { return reference_wrapper<_Tp>(__t); }

  // Denotes a const reference should be taken to a variable.
  template<typename _Tp>
    inline reference_wrapper<const _Tp>
    cref(const _Tp& __t)
    { return reference_wrapper<const _Tp>(__t); }

  template<typename _Tp>
    inline reference_wrapper<_Tp>
    ref(reference_wrapper<_Tp> __t)
    { return ref(__t.get()); }

  template<typename _Tp>
    inline reference_wrapper<const _Tp>
    cref(reference_wrapper<_Tp> __t)
    { return cref(__t.get()); }

   template<typename _Tp, bool>
     struct _Mem_fn_const_or_non
     {
       typedef const _Tp& type;
     };

    template<typename _Tp>
      struct _Mem_fn_const_or_non<_Tp, false>
      {
        typedef _Tp& type;
      };

  template<typename _Res, typename _Class>
  class _Mem_fn<_Res _Class::*>
  {
    // This bit of genius is due to Peter Dimov, improved slightly by
    // Douglas Gregor.
    template<typename _Tp>
      _Res&
      _M_call(_Tp& __object, _Class *) const
      { return __object.*__pm; }

    template<typename _Tp, typename _Up>
      _Res&
      _M_call(_Tp& __object, _Up * const *) const
      { return (*__object).*__pm; }

    template<typename _Tp, typename _Up>
      const _Res&
      _M_call(_Tp& __object, const _Up * const *) const
      { return (*__object).*__pm; }

    template<typename _Tp>
      const _Res&
      _M_call(_Tp& __object, const _Class *) const
      { return __object.*__pm; }

    template<typename _Tp>
      const _Res&
      _M_call(_Tp& __ptr, const volatile void*) const
      { return (*__ptr).*__pm; }

    template<typename _Tp> static _Tp& __get_ref();

    template<typename _Tp>
      static __sfinae_types::__one __check_const(_Tp&, _Class*);
    template<typename _Tp, typename _Up>
      static __sfinae_types::__one __check_const(_Tp&, _Up * const *);
    template<typename _Tp, typename _Up>
      static __sfinae_types::__two __check_const(_Tp&, const _Up * const *);
    template<typename _Tp>
      static __sfinae_types::__two __check_const(_Tp&, const _Class*);
    template<typename _Tp>
      static __sfinae_types::__two __check_const(_Tp&, const volatile void*);

  public:
    template<typename _Tp>
      struct _Result_type
      : _Mem_fn_const_or_non<
        _Res,
        (sizeof(__sfinae_types::__two)
	 == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))>
      { };

    template<typename _Signature>
      struct result;

    template<typename _CVMem, typename _Tp>
      struct result<_CVMem(_Tp)>
      : public _Result_type<_Tp> { };

    template<typename _CVMem, typename _Tp>
      struct result<_CVMem(_Tp&)>
      : public _Result_type<_Tp> { };

    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 _Tp>
      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<typename _Tp, typename _Class>
    inline _Mem_fn<_Tp _Class::*>
    mem_fn(_Tp _Class::* __pm)
    {
      return _Mem_fn<_Tp _Class::*>(__pm);
    }

  /**
   *  @brief Determines if the given type _Tp is a function object
   *  should be treated as a subexpression when evaluating calls to
   *  function objects returned by bind(). [TR1 3.6.1]
   */
  template<typename _Tp>
    struct is_bind_expression
    { static const bool value = false; };

  template<typename _Tp>
    const bool is_bind_expression<_Tp>::value;

  /**
   *  @brief Determines if the given type _Tp is a placeholder in a
   *  bind() expression and, if so, which placeholder it is. [TR1 3.6.2]
   */
  template<typename _Tp>
    struct is_placeholder
    { static const int value = 0; };

  template<typename _Tp>
    const int is_placeholder<_Tp>::value;

  /**
   *  @if maint
   *  The type of placeholder objects defined by libstdc++.
   *  @endif
   */
  template<int _Num> struct _Placeholder { };

  /**
   *  @if maint
   *  Partial specialization of is_placeholder that provides the placeholder
   *  number for the placeholder objects defined by libstdc++.
   *  @endif
   */
  template<int _Num>
    struct is_placeholder<_Placeholder<_Num> >
    { static const int value = _Num; };

  template<int _Num>
    const int is_placeholder<_Placeholder<_Num> >::value;

  /**
   *  @if maint
   *  Maps an argument to bind() into an actual argument to the bound
   *  function object [TR1 3.6.3/5]. Only the first parameter should
   *  be specified: the rest are used to determine among the various
   *  implementations. Note that, although this class is a function
   *  object, isn't not entirely normal because it takes only two
   *  parameters regardless of the number of parameters passed to the
   *  bind expression. The first parameter is the bound argument and
   *  the second parameter is a tuple containing references to the
   *  rest of the arguments.
   *  @endif
   */
  template<typename _Arg,
           bool _IsBindExp = is_bind_expression<_Arg>::value,
           bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
    class _Mu;

  /**
   *  @if maint
   *  If the argument is reference_wrapper<_Tp>, returns the
   *  underlying reference. [TR1 3.6.3/5 bullet 1]
   *  @endif
   */
  template<typename _Tp>
    class _Mu<reference_wrapper<_Tp>, false, false>
    {
    public:
      typedef _Tp& result_type;

      /* Note: This won't actually work for const volatile
       * reference_wrappers, because reference_wrapper::get() is const
       * but not volatile-qualified. This might be a defect in the TR.
       */
      template<typename _CVRef, typename _Tuple>
      result_type
      operator()(_CVRef& __arg, const _Tuple&) const volatile
      { return __arg.get(); }
    };

  /**
   *  @if maint
   *  If the argument is a bind expression, we invoke the underlying
   *  function object with the same cv-qualifiers as we are given and
   *  pass along all of our arguments (unwrapped). [TR1 3.6.3/5 bullet 2]
   *  @endif
   */
  template<typename _Arg>
    class _Mu<_Arg, true, false>
    {
    public:
      template<typename _Signature> class result;

#define _GLIBCXX_REPEAT_HEADER <tr1/mu_iterate.h>
#  include <tr1/repeat.h>
#undef _GLIBCXX_REPEAT_HEADER
    };

  /**
   *  @if maint
   *  If the argument is a placeholder for the Nth argument, returns
   *  a reference to the Nth argument to the bind function object.
   *  [TR1 3.6.3/5 bullet 3]
   *  @endif
   */
  template<typename _Arg>
    class _Mu<_Arg, false, true>
    {
    public:
      template<typename _Signature> class result;

      template<typename _CVMu, typename _CVArg, typename _Tuple>
      class result<_CVMu(_CVArg, _Tuple)>
      {
        // Add a reference, if it hasn't already been done for us.
        // This allows us to be a little bit sloppy in constructing
        // the tuple that we pass to result_of<...>.
        typedef typename tuple_element<(is_placeholder<_Arg>::value - 1),
                                       _Tuple>::type __base_type;

      public:
        typedef typename add_reference<__base_type>::type type;
      };

      template<typename _Tuple>
      typename result<_Mu(_Arg, _Tuple)>::type
      operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile
      {
        return ::std::tr1::get<(is_placeholder<_Arg>::value - 1)>(__tuple);
      }
    };

  /**
   *  @if maint
   *  If the argument is just a value, returns a reference to that
   *  value. The cv-qualifiers on the reference are the same as the
   *  cv-qualifiers on the _Mu object. [TR1 3.6.3/5 bullet 4]
   *  @endif
   */
  template<typename _Arg>
    class _Mu<_Arg, false, false>
    {
    public:
      template<typename _Signature> struct result;

      template<typename _CVMu, typename _CVArg, typename _Tuple>
      struct result<_CVMu(_CVArg, _Tuple)>
      {
        typedef typename add_reference<_CVArg>::type type;
      };

      // Pick up the cv-qualifiers of the argument
      template<typename _CVArg, typename _Tuple>
      _CVArg& operator()(_CVArg& __arg, const _Tuple&) const volatile
      { return __arg; }
    };

  /**
   *  @if maint
   *  Maps member pointers into instances of _Mem_fn but leaves all
   *  other function objects untouched. Used by tr1::bind(). The
   *  primary template handles the non--member-pointer case.
   *  @endif
   */
  template<typename _Tp>
    struct _Maybe_wrap_member_pointer
    {
      typedef _Tp type;
      static const _Tp& __do_wrap(const _Tp& __x) { return __x; }
    };

  /**
   *  @if maint
   *  Maps member pointers into instances of _Mem_fn but leaves all
   *  other function objects untouched. Used by tr1::bind(). This
   *  partial specialization handles the member pointer case.
   *  @endif
   */
  template<typename _Tp, typename _Class>
    struct _Maybe_wrap_member_pointer<_Tp _Class::*>
    {
      typedef _Mem_fn<_Tp _Class::*> type;
      static type __do_wrap(_Tp _Class::* __pm) { return type(__pm); }
    };

  /**
   *  @if maint
   *  Type of the function object returned from bind().
   *  @endif
   */
   template<typename _Signature>
     struct _Bind;

  /**
   *  @if maint
   *  Type of the function object returned from bind<R>().
   *  @endif
   */
   template<typename _Result, typename _Signature>
     struct _Bind_result;

  /**
   *  @if maint
   *  Class template _Bind is always a bind expression.
   *  @endif
   */
   template<typename _Signature>
     struct is_bind_expression<_Bind<_Signature> >
     { static const bool value = true; };

   template<typename _Signature>
     const bool is_bind_expression<_Bind<_Signature> >::value;

  /**
   *  @if maint
   *  Class template _Bind_result is always a bind expression.
   *  @endif
   */
   template<typename _Result, typename _Signature>
     struct is_bind_expression<_Bind_result<_Result, _Signature> >
     { static const bool value = true; };

   template<typename _Result, typename _Signature>
     const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value;

  /**
   *  @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<typename _Tp>
    struct __is_location_invariant
    : integral_constant<bool,
                        (is_pointer<_Tp>::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<typename _Tp> _Tp& _M_access()
    { return *static_cast<_Tp*>(_M_access()); }

    template<typename _Tp> const _Tp& _M_access() const
    { return *static_cast<const _Tp*>(_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<typename _Tp>
    struct _Simple_type_wrapper
    {
      _Simple_type_wrapper(_Tp __value) : __value(__value) { }

      _Tp __value;
    };

  template<typename _Tp>
    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<typename _Functor>
    inline _Functor& __callable_functor(_Functor& __f) { return __f; }

  template<typename _Member, typename _Class>
    inline _Mem_fn<_Member _Class::*>
    __callable_functor(_Member _Class::* &__p)
    { return mem_fn(__p); }

  template<typename _Member, typename _Class>
    inline _Mem_fn<_Member _Class::*>
    __callable_functor(_Member _Class::* const &__p)
    { return mem_fn(__p); }

  template<typename _Signature, typename _Functor>
    class _Function_handler;

  template<typename _Signature>
    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<typename _Functor>
    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<bool, __stored_locally> _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<const type_info*>() = &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<typename _Signature>
      static bool
      _M_not_empty_function(const function<_Signature>& __f)
      {
        return __f;
      }

      template<typename _Tp>
      static bool
      _M_not_empty_function(const _Tp*& __fp)
      {
        return __fp;
      }

      template<typename _Class, typename _Tp>
      static bool
      _M_not_empty_function(_Tp _Class::* const& __mp)
      {
        return __mp;
      }

      template<typename _Tp>
      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<typename _Functor>
    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<const type_info*>() = &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;
  };

  // [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<typename _Signature>
    inline bool
    operator==(const function<_Signature>& __f, _M_clear_type*)
    {
      return !__f;
    }

  /**
   *  @overload
   */
  template<typename _Signature>
    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<typename _Signature>
    inline bool
    operator!=(const function<_Signature>& __f, _M_clear_type*)
    {
      return __f;
    }

  /**
   *  @overload
   */
  template<typename _Signature>
    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<typename _Signature>
    inline void
    swap(function<_Signature>& __x, function<_Signature>& __y)
    {
      __x.swap(__y);
    }

_GLIBCXX_END_NAMESPACE
}

#define _GLIBCXX_JOIN(X,Y) _GLIBCXX_JOIN2( X , Y )
#define _GLIBCXX_JOIN2(X,Y) _GLIBCXX_JOIN3(X,Y)
#define _GLIBCXX_JOIN3(X,Y) X##Y
#define _GLIBCXX_REPEAT_HEADER <tr1/functional_iterate.h>
#include <tr1/repeat.h>
#undef _GLIBCXX_REPEAT_HEADER
#undef _GLIBCXX_JOIN3
#undef _GLIBCXX_JOIN2
#undef _GLIBCXX_JOIN

#include <tr1/functional_hash.h>

#endif


code:
// TR1 functional -*- C++ -*-

// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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 tr1/functional_hash.h
 *  This is an internal header file, included by other library headers.
 *  You should not attempt to use it directly.
 */

#ifndef _TR1_FUNCTIONAL_HASH_H
#define _TR1_FUNCTIONAL_HASH_H 1

#include <string>
#include <cmath>  // for std::frexp

namespace std
{
_GLIBCXX_BEGIN_NAMESPACE(tr1)

  // Definition of default hash function std::tr1::hash<>.  The types for
  // which std::tr1::hash<T> is defined is in clause 6.3.3. of the PDTR.
  template<typename T>
    struct hash;

#define _TR1_hashtable_define_trivial_hash(_Tp)         \
  template<>                                            \
    struct hash<_Tp>                                    \
    : public std::unary_function<_Tp, std::size_t>      \
    {                                                   \
      std::size_t                                       \
      operator()(_Tp __val) const                       \
      { return static_cast<std::size_t>(__val); }       \
    }

  _TR1_hashtable_define_trivial_hash(bool);
  _TR1_hashtable_define_trivial_hash(char);
  _TR1_hashtable_define_trivial_hash(signed char);
  _TR1_hashtable_define_trivial_hash(unsigned char);
  _TR1_hashtable_define_trivial_hash(wchar_t);
  _TR1_hashtable_define_trivial_hash(short);
  _TR1_hashtable_define_trivial_hash(int);
  _TR1_hashtable_define_trivial_hash(long);
  _TR1_hashtable_define_trivial_hash(long long);
  _TR1_hashtable_define_trivial_hash(unsigned short);
  _TR1_hashtable_define_trivial_hash(unsigned int);
  _TR1_hashtable_define_trivial_hash(unsigned long);
  _TR1_hashtable_define_trivial_hash(unsigned long long);

#undef _TR1_hashtable_define_trivial_hash

  template<typename _Tp>
    struct hash<_Tp*>
    : public std::unary_function<_Tp*, std::size_t>
    {
      std::size_t
      operator()(_Tp* __p) const
      { return reinterpret_cast<std::size_t>(__p); }
    };

  // Fowler / Noll / Vo (FNV) Hash (type FNV-1a)
  // (used by the next specializations of std::tr1::hash<>)

  // Dummy generic implementation (for sizeof(size_t) != 4, 8).
  template<std::size_t = sizeof(std::size_t)>
    struct _Fnv_hash
    {
      static std::size_t
      hash(const char* __first, std::size_t __length)
      {
	std::size_t __result = 0;
	for (; __length > 0; --__length)
	  __result = (__result * 131) + *__first++;
	return __result;
      }
    };

  template<>
    struct _Fnv_hash<4>
    {
      static std::size_t
      hash(const char* __first, std::size_t __length)
      {
	std::size_t __result = static_cast<std::size_t>(2166136261UL);
	for (; __length > 0; --__length)
	  {
	    __result ^= static_cast<std::size_t>(*__first++);
	    __result *= static_cast<std::size_t>(16777619UL);
	  }
	return __result;
      }
    };

  template<>
    struct _Fnv_hash<8>
    {
      static std::size_t
      hash(const char* __first, std::size_t __length)
      {
	std::size_t __result =
	  static_cast<std::size_t>(14695981039346656037ULL);
	for (; __length > 0; --__length)
	  {
	    __result ^= static_cast<std::size_t>(*__first++);
	    __result *= static_cast<std::size_t>(1099511628211ULL);
	  }
	return __result;
      }
    };

  // XXX String and floating point hashes probably shouldn't be inline
  // member functions, since are nontrivial.  Once we have the framework
  // for TR1 .cc files, these should go in one.
  template<>
    struct hash<std::string>
    : public std::unary_function<std::string, std::size_t>
    {
      std::size_t
      operator()(const std::string& __s) const
      { return _Fnv_hash<>::hash(__s.data(), __s.length()); }
    };

#ifdef _GLIBCXX_USE_WCHAR_T
  template<>
    struct hash<std::wstring>
    : public std::unary_function<std::wstring, std::size_t>
    {
      std::size_t
      operator()(const std::wstring& __s) const
      {
	return _Fnv_hash<>::hash(reinterpret_cast<const char*>(__s.data()),
				 __s.length() * sizeof(wchar_t));
      }
    };
#endif

  template<>
    struct hash<float>
    : public std::unary_function<float, std::size_t>
    {
      std::size_t
      operator()(float __fval) const
      {
	std::size_t __result = 0;

	// 0 and -0 both hash to zero.
	if (__fval != 0.0f)
	  __result = _Fnv_hash<>::hash(reinterpret_cast<const char*>(&__fval),
				       sizeof(__fval));
	return __result;
      }
    };

  template<>
    struct hash<double>
    : public std::unary_function<double, std::size_t>
    {
      std::size_t
      operator()(double __dval) const
      {
	std::size_t __result = 0;

	// 0 and -0 both hash to zero.
	if (__dval != 0.0)
	  __result = _Fnv_hash<>::hash(reinterpret_cast<const char*>(&__dval),
				       sizeof(__dval));
	return __result;
      }
    };

  // For long double, careful with random padding bits (e.g., on x86,
  // 10 bytes -> 12 bytes) and resort to frexp.
  template<>
    struct hash<long double>
    : public std::unary_function<long double, std::size_t>
    {
      std::size_t
      operator()(long double __ldval) const
      {
	std::size_t __result = 0;

	int __exponent;
	__ldval = std::frexp(__ldval, &__exponent);
	__ldval = __ldval < 0.0l ? -(__ldval + 0.5l) : __ldval;

	const long double __mult =
	  std::numeric_limits<std::size_t>::max() + 1.0l;
	__ldval *= __mult;

	// Try to use all the bits of the mantissa (really necessary only
	// on 32-bit targets, at least for 80-bit floating point formats).
	const std::size_t __hibits = (std::size_t)__ldval;
	__ldval = (__ldval - (long double)__hibits) * __mult;

	const std::size_t __coeff =
	  (std::numeric_limits<std::size_t>::max()
	   / std::numeric_limits<long double>::max_exponent);

	__result = __hibits + (std::size_t)__ldval + __coeff * __exponent;

	return __result;
      }
    };

_GLIBCXX_END_NAMESPACE
}

#endif


code:
// TR1 functional -*- C++ -*-

// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
// Written by Douglas Gregor <doug.gregor -at- gmail.com>
//
// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// 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 tr1/functional_iterate.h
 *  This is an internal header file, included by other library headers.
 *  You should not attempt to use it directly.
 */

namespace std
{
_GLIBCXX_BEGIN_NAMESPACE(tr1)

template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  struct _Weak_result_type_impl<_Res(_GLIBCXX_TEMPLATE_ARGS)>
  {
    typedef _Res result_type;
  };

template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  struct _Weak_result_type_impl<_Res (&)(_GLIBCXX_TEMPLATE_ARGS)>
  {
    typedef _Res result_type;
  };

template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  struct _Weak_result_type_impl<_Res (*)(_GLIBCXX_TEMPLATE_ARGS)>
  {
    typedef _Res result_type;
  };

#if _GLIBCXX_NUM_ARGS > 0
template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  struct _Weak_result_type_impl<
           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED)>
  {
    typedef _Res result_type;
  };

template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  struct _Weak_result_type_impl<
           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const>
  {
    typedef _Res result_type;
  };

template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  struct _Weak_result_type_impl<
           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile>
  {
    typedef _Res result_type;
  };

template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  struct _Weak_result_type_impl<
           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const volatile>
  {
    typedef _Res result_type;
  };
#endif

template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  class result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>
    : public _Result_of_impl<
               _Has_result_type<_Weak_result_type<_Functor> >::value,
             _Functor(_GLIBCXX_TEMPLATE_ARGS)>
  { };

template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  struct _Result_of_impl<true, _Functor(_GLIBCXX_TEMPLATE_ARGS)>
  {
    typedef typename _Weak_result_type<_Functor>::result_type type;
  };

template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  struct _Result_of_impl<false, _Functor(_GLIBCXX_TEMPLATE_ARGS)>
  {
#if _GLIBCXX_NUM_ARGS > 0
    typedef typename _Functor
              ::template result<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type type;
#else
    typedef void type;
#endif
  };

/**
 * @if maint
 * Invoke a function object, which may be either a member pointer or a
 * function object. The first parameter will tell which.
 * @endif
 */
template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  inline
  typename __gnu_cxx::__enable_if<(!is_member_pointer<_Functor>::value
			&& !is_function<_Functor>::value
              && !is_function<typename remove_pointer<_Functor>::type>::value),
           typename result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type>::__type
  __invoke(_Functor& __f _GLIBCXX_COMMA _GLIBCXX_REF_PARAMS)
  {
    return __f(_GLIBCXX_ARGS);
  }

#if _GLIBCXX_NUM_ARGS > 0
template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  inline
  typename __gnu_cxx::__enable_if<(is_member_pointer<_Functor>::value
			&& !is_function<_Functor>::value
              && !is_function<typename remove_pointer<_Functor>::type>::value),
             typename result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type
           >::__type
  __invoke(_Functor& __f _GLIBCXX_COMMA _GLIBCXX_REF_PARAMS)
  {
    return mem_fn(__f)(_GLIBCXX_ARGS);
  }
#endif

// To pick up function references (that will become function pointers)
template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  inline
  typename __gnu_cxx::__enable_if<(is_pointer<_Functor>::value
	&& is_function<typename remove_pointer<_Functor>::type>::value),
             typename result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type
           >::__type
  __invoke(_Functor __f _GLIBCXX_COMMA _GLIBCXX_REF_PARAMS)
  {
    return __f(_GLIBCXX_ARGS);
  }

/**
 * @if maint
 * Implementation of reference_wrapper::operator()
 * @endif
*/
#if _GLIBCXX_NUM_ARGS > 0
template<typename _Tp>
template<_GLIBCXX_TEMPLATE_PARAMS>
  typename result_of<
   typename reference_wrapper<_Tp>::_M_func_type(_GLIBCXX_TEMPLATE_ARGS)>::type
  reference_wrapper<_Tp>::operator()(_GLIBCXX_REF_PARAMS) const
  {
    return __invoke(get(), _GLIBCXX_ARGS);
  }
#endif

#if _GLIBCXX_NUM_ARGS > 0
template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  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<typename _Tp>
      _Res
      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED
              _GLIBCXX_PARAMS_SHIFTED) const
      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }

    template<typename _Tp>
      _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 __pf) : __pmf(__pf) { }

    // 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<typename _Tp>
      _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<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const>
#if _GLIBCXX_NUM_ARGS == 1
  : public unary_function<const _Class*, _Res>
#elif _GLIBCXX_NUM_ARGS == 2
    : public binary_function<const _Class*, _T1, _Res>
#endif
  {
    typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const;

     template<typename _Tp>
      _Res
      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED
              _GLIBCXX_PARAMS_SHIFTED) const
      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }

    template<typename _Tp>
      _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 __pf) : __pmf(__pf) { }

    // 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<typename _Tp>
      _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<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile>
#if _GLIBCXX_NUM_ARGS == 1
  : public unary_function<volatile _Class*, _Res>
#elif _GLIBCXX_NUM_ARGS == 2
    : public binary_function<volatile _Class*, _T1, _Res>
#endif
  {
    typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile;

    template<typename _Tp>
      _Res
      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED
              _GLIBCXX_PARAMS_SHIFTED) const
      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }

    template<typename _Tp>
      _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 __pf) : __pmf(__pf) { }

    // 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<typename _Tp>
      _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<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>
  class _Mem_fn<_Res(_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const volatile>
#if _GLIBCXX_NUM_ARGS == 1
  : public unary_function<const volatile _Class*, _Res>
#elif _GLIBCXX_NUM_ARGS == 2
    : public binary_function<const volatile _Class*, _T1, _Res>
#endif
  {
    typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED)
              const volatile;

    template<typename _Tp>
      _Res
      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED
              _GLIBCXX_PARAMS_SHIFTED) const
      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }

    template<typename _Tp>
      _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 __pf) : __pmf(__pf) { }

    // 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<typename _Tp>
      _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

#if _GLIBCXX_NUM_ARGS > 0
namespace placeholders
{
namespace
{
   _Placeholder<_GLIBCXX_NUM_ARGS> _GLIBCXX_JOIN(_,_GLIBCXX_NUM_ARGS);
} // anonymous namespace
}
#endif

template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
class _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)>
  : public _Weak_result_type<_Functor>
{
  typedef _Bind __self_type;

  _Functor _M_f;
  _GLIBCXX_BIND_MEMBERS

 public:
#if _GLIBCXX_NUM_ARGS == 0
  explicit
#endif
  _Bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
    : _M_f(__f) _GLIBCXX_COMMA _GLIBCXX_BIND_MEMBERS_INIT { }

#define _GLIBCXX_BIND_REPEAT_HEADER <tr1/bind_iterate.h>
#include <tr1/bind_repeat.h>
#undef _GLIBCXX_BIND_REPEAT_HEADER
};

template<typename _Result, typename _Functor
         _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
class _Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>
{
  _Functor _M_f;
  _GLIBCXX_BIND_MEMBERS

 public:
  typedef _Result result_type;

#if _GLIBCXX_NUM_ARGS == 0
  explicit
#endif
  _Bind_result(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
    : _M_f(__f) _GLIBCXX_COMMA _GLIBCXX_BIND_MEMBERS_INIT { }

#define _GLIBCXX_BIND_REPEAT_HEADER <tr1/bind_iterate.h>
#define _GLIBCXX_BIND_HAS_RESULT_TYPE
#include <tr1/bind_repeat.h>
#undef _GLIBCXX_BIND_HAS_RESULT_TYPE
#undef _GLIBCXX_BIND_REPEAT_HEADER
};

// Handle arbitrary function objects
template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
inline
_Bind<typename _Maybe_wrap_member_pointer<_Functor>::type
        (_GLIBCXX_TEMPLATE_ARGS)>
bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
{
  typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
  typedef typename __maybe_type::type __functor_type;
  typedef _Bind<__functor_type(_GLIBCXX_TEMPLATE_ARGS)> __result_type;
  return __result_type(__maybe_type::__do_wrap(__f)
                       _GLIBCXX_COMMA _GLIBCXX_ARGS);
}

template<typename _Result, typename _Functor
         _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
inline
_Bind_result<_Result,
             typename _Maybe_wrap_member_pointer<_Functor>::type
               (_GLIBCXX_TEMPLATE_ARGS)>
bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
{
  typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
  typedef typename __maybe_type::type __functor_type;
  typedef _Bind_result<_Result, __functor_type(_GLIBCXX_TEMPLATE_ARGS)>
    __result_type;
  return __result_type(__maybe_type::__do_wrap(__f)
                       _GLIBCXX_COMMA _GLIBCXX_ARGS);
}

template<typename _Res, typename _Functor _GLIBCXX_COMMA
         _GLIBCXX_TEMPLATE_PARAMS>
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<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
class _Function_handler<void(_GLIBCXX_TEMPLATE_ARGS), _Functor>
  : 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<typename _Res, typename _Functor _GLIBCXX_COMMA
         _GLIBCXX_TEMPLATE_PARAMS>
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<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
class _Function_handler<void(_GLIBCXX_TEMPLATE_ARGS),
                        reference_wrapper<_Functor> >
  : 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<typename _Class, typename _Member, typename _Res
         _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
class _Function_handler<_Res(_GLIBCXX_TEMPLATE_ARGS), _Member _Class::*>
  : public _Function_handler<void(_GLIBCXX_TEMPLATE_ARGS), _Member _Class::*>
{
  typedef _Function_handler<void(_GLIBCXX_TEMPLATE_ARGS), _Member _Class::*>
    _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<typename _Class, typename _Member
         _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
class _Function_handler<void(_GLIBCXX_TEMPLATE_ARGS), _Member _Class::*>
  : 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<const type_info*>() = &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<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
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<F>, 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<F>, this function will not throw.
   */
  template<typename _Functor>
    function(_Functor __f,
             typename __gnu_cxx::__enable_if<!is_integral<_Functor>::value, _Useless>::__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<F>, 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<F>, this function will not throw.
   */
  template<typename _Functor>
    typename __gnu_cxx::__enable_if<!is_integral<_Functor>::value, function&>::__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<typename _Functor>       _Functor* target();

  /**
   *  @overload
   */
  template<typename _Functor> const _Functor* target() const;

 private:
  // [3.7.2.6] undefined operators
  template<typename _Function>
    void operator==(const function<_Function>&) const;
  template<typename _Function>
    void operator!=(const function<_Function>&) const;

  typedef _Res (*_Invoker_type)(const _Any_data& _GLIBCXX_COMMA
                                _GLIBCXX_PARAMS);
  _Invoker_type _M_invoker;
};

template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  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<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
template<typename _Functor>
  function<_Res(_GLIBCXX_TEMPLATE_ARGS)>
  ::function(_Functor __f,
        typename __gnu_cxx::__enable_if<!is_integral<_Functor>::value, _Useless>::__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<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  _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<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
  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<const type_info*>();
      }
    else
      {
        return typeid(void);
      }
  }

template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
template<typename _Functor>
  _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<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
template<typename _Functor>
  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<const _Functor*>();
      }
    else
      {
        return 0;
      }
  }

_GLIBCXX_END_NAMESPACE
}