?? functional
字號:
// functional standard header
#pragma once
#ifndef _FUNCTIONAL_
#define _FUNCTIONAL_
#ifndef RC_INVOKED
#include <xfunctional>
#pragma pack(push,_CRT_PACKING)
#pragma warning(push,3)
#pragma push_macro("new")
#undef new
#if _HAS_TR1
#include <exception>
#include <typeinfo>
#include <xrefwrap>
#pragma warning(disable: 4100 4180 4244)
_STD_BEGIN
namespace tr1 { // TR1 additions
// IMPLEMENT _STD tr1::mem_fn
// TEMPLATE FUNCTION mem_fn
template<class _Rx,
class _Arg0>
_Call_wrapper<_Callable_pmd<_Rx _Arg0::*const, _Arg0> >
mem_fn(_Rx _Arg0::*const _Pmd)
{ // return data object wrapper
return (_Call_wrapper<_Callable_pmd<_Rx _Arg0::*const, _Arg0> >(_Pmd));
}
// define multiple-argument variants of mem_fn
#define _INCL_FILE_xxmem_fn
#define _NOZERO
#include <xfwrap>
// IMPLEMENT _STD tr1::function
#if _NO_SFINAE
#define _NOT_INTEGRAL(ty)
#if defined(_NATIVE_NULLPTR_SUPPORTED) \
&& !defined(_DO_NOT_USE_NULLPTR_IN_STL)
typedef _STD nullptr_t _Unutterable;
#else /* defined(_NATIVE_NULLPTR_SUPPORTED) etc. */
typedef int _Unutterable;
#endif /* defined(_NATIVE_NULLPTR_SUPPORTED) etc. */
#else /* _NO_SFINAE */
template<bool,
class _Ty>
struct _Not_integral;
template<class _Ty>
struct _Not_integral<true, _Ty>
{ // distinguish non-integral types
typedef _Ty _Type;
};
#define _NOT_INTEGRAL(ty) , \
typename _Not_integral<!_Is_integral<ty>::value, int>::_Type = 0
typedef struct _Unnamed *_Unutterable;
#endif /* _NO_SFINAE */
// CLASS bad_function_call
class bad_function_call
: public exception
{ // null function pointer exception
public:
explicit bad_function_call(const char * = 0)
{ // construct with ignored message
}
virtual const char *__CLR_OR_THIS_CALL what() const _THROW0()
{ // return pointer to message string
return ("bad function call");
}
};
_CRTIMP2_PURE __declspec(noreturn) void __CLRCALL_PURE_OR_CDECL _Xfunc();
template<class _Tx>
struct _Get_function_impl;
#define _INCL_FILE_xxfunction
#include <xfwrap>
// TEMPLATE CLASS function
template<class _Fty>
class function
: public _Get_function_impl<_Fty>::_Type
{ // wrapper for callable objects
public:
typedef function<_Fty> _Myt;
typedef typename _Get_function_impl<_Fty>::_Type _Mybase;
function()
{ // construct empty function wrapper
this->_Reset();
}
function(const _Myt& _Right)
{ // construct holding copy of _Right
this->_Reset((const _Mybase&)_Right);
}
template<class _Fx>
function(_Fx _Func _NOT_INTEGRAL(_Fx))
{ // construct wrapper holding copy of _Func
this->_Reset(_Func);
}
template<class _Fx,
class _Alloc>
function(_Fx _Func _NOT_INTEGRAL(_Fx), const _Alloc& _Ax)
{ // construct wrapper holding copy of _Func
this->_Reset_alloc(_Func, _Ax);
}
template<class _Fx>
function(reference_wrapper<_Fx> _Func)
{ // construct wrapper holding reference to_Func
this->_Reset(_Func);
}
template<class _Fx,
class _Alloc>
function(reference_wrapper<_Fx> _Func, const _Alloc& _Ax)
{ // construct wrapper holding reference to_Func
this->_Reset_alloc(_Func, _Ax);
}
function(_Unutterable)
{ // construct empty function wrapper from null pointer
this->_Reset();
}
#if defined(_NATIVE_NULLPTR_SUPPORTED) \
&& !defined(_DO_NOT_USE_NULLPTR_IN_STL)
function(int)
{ // construct empty function wrapper from null pointer
this->_Reset();
}
#endif /* defined(_NATIVE_NULLPTR_SUPPORTED) etc. */
~function()
{ // destroy the object
this->_Tidy();
}
_Myt& operator=(const _Myt& _Right)
{ // assign _Right
if (this != &_Right)
{ // clean up and copy
this->_Tidy();
this->_Reset((const _Mybase&)_Right);
}
return (*this);
}
function(_Myt&& _Right)
{ // construct holding moved copy of _Right
this->_Resetm((_Mybase&)_Right);
}
_Myt& operator=(_Myt&& _Right)
{ // assign by moving _Right
if (this != &_Right)
{ // clean up and copy
this->_Tidy();
this->_Resetm((_Mybase&)_Right);
}
return (*this);
}
template<class _Fx>
_Myt& operator=(_Fx _Func _NOT_INTEGRAL(_Fx))
{ // assign function object _Func
this->_Tidy();
this->_Reset(_Func);
return (*this);
}
function& operator=(_Unutterable)
{ // clear function object
this->_Tidy();
this->_Reset();
return (*this);
}
#if defined(_NATIVE_NULLPTR_SUPPORTED) \
&& !defined(_DO_NOT_USE_NULLPTR_IN_STL)
function& operator=(int)
{ // clear function object
this->_Tidy();
this->_Reset();
return (*this);
}
#endif /* defined(_NATIVE_NULLPTR_SUPPORTED) etc. */
template<class _Fx>
_Myt& operator=(reference_wrapper<_Fx> _Func)
{ // assign wrapper holding reference to_Func
this->_Tidy();
this->_Reset(_Func);
return (*this);
}
template<class _Fx,
class _Alloc>
void assign(_Fx _Func _NOT_INTEGRAL(_Fx), const _Alloc& _Ax)
{ // construct wrapper holding copy of _Func
this->_Tidy();
this->_Reset_alloc(_Func, _Ax);
}
template<class _Fx,
class _Alloc>
void assign(reference_wrapper<_Fx> _Func, const _Alloc& _Ax)
{ // construct wrapper holding reference to_Func
this->_Tidy();
this->_Reset_alloc(_Func, _Ax);
}
void swap(_Myt& _Right)
{ // swap with _Right
this->_Swap(_Right);
}
_OPERATOR_BOOL() const
{ // test if wrapper holds null function pointer
return (!this->_Empty() ? _CONVERTIBLE_TO_TRUE : 0);
}
const _XSTD2 type_info& target_type() const
{ // return type_info object for target type
return (this->_Target_type());
}
template<class _Fty2>
_Fty2 *target()
{ // return pointer to target object
return ((_Fty2*)this->_Target(typeid(_Fty2)));
}
template<class _Fty2>
const _Fty2 *target() const
{ // return pointer to target object
return ((const _Fty2*)this->_Target(typeid(_Fty2)));
}
private:
template<class _Fty2>
void operator==(const function<_Fty2>&); // not defined
template<class _Fty2>
void operator!=(const function<_Fty2>&); // not defined
};
// TEMPLATE FUNCTION swap
template<class _Fty>
void swap(function<_Fty>& _Left, function<_Fty>& _Right)
{ // swap contents of _Left with contents of _Right
_Left.swap(_Right);
}
// TEMPLATE NULL POINTER COMPARISONS
template<class _Fty>
bool operator==(const function<_Fty>& _Other, _Unutterable)
{ // compare to null pointer
return (!_Other);
}
template<class _Fty>
bool operator==(_Unutterable _Npc, const function<_Fty>& _Other)
{ // compare to null pointer
return (operator==(_Other, _Npc));
}
template<class _Fty>
bool operator!=(const function<_Fty>& _Other, _Unutterable _Npc)
{ // compare to null pointer
return (!operator==(_Other, _Npc));
}
template<class _Fty>
bool operator!=(_Unutterable _Npc, const function<_Fty>& _Other)
{ // compare to null pointer
return (!operator==(_Other, _Npc));
}
// IMPLEMENT _STD tr1::bind
// PLACEHOLDERS
template<int _Nx>
class _Ph
{ // placeholder
};
template<class _Tx>
struct is_placeholder
{ // template to indicate that _Tx is not a placeholder
static const int value = 0;
};
template<int _Nx>
struct is_placeholder<_Ph<_Nx> >
{ // template specialization to indicate that _Ph<_Nx> is a placeholder
static const int value = _Nx;
};
// TEMPLATE CLASS is_bind_expression
template<class _Tx>
struct is_bind_expression
{ // template to indicate that _Tx is not a bind expression
static const bool value = false;
};
// TEMPLATE CLASS _Notforced
struct _Notforced
{ // operator() returns result_of<...>::type
};
// TEMPLATE STRUCT _Bindret
template<class _Override,
class _Natural>
struct _Bindret
{ // use user-specified override
typedef _Override _Type;
};
template<class _Natural>
struct _Bindret<_Notforced, _Natural>
{ // use natural type
typedef _Natural _Type;
};
// TEMPLATE CLASS _Wrap_result_type
template<bool _Has_nested,
class _Ty>
struct _Wrap_result_type;
template<class _Ty>
struct _Wrap_result_type<false, _Ty>
{ // _Ty does not have nested result_type
};
template<class _Ty>
struct _Wrap_result_type<true, _Ty>
{ // _Ty has nested result_type
typedef typename _Ty::result_type result_type;
};
// TEMPLATE CLASS _Bind
template<class _Ret,
class _BindN>
class _Bind_base
{ // template base class for objects returned by bind
public:
typedef typename _BindN::_MyTy _MyTy;
typedef _BindN _MyBind;
_Bind_base(_BindN _B0)
: _Bx(_B0)
{ // construct
}
// define operator() member functions:
#define _INCL_FILE_xxbind0
#include <xawrap>
private:
_BindN _Bx;
};
template<class _Result_type,
class _Ret,
class _BindN>
class _Bind
: public _Bind_base<_Ret, _BindN>
{ // template class for objects returned by bind with known result_type
public:
_Bind(_BindN _B0)
: _Bind_base<_Ret, _BindN>(_B0)
{ // construct
}
typedef _Result_type result_type;
};
template<class _Ret,
class _BindN>
class _Bind<_Notforced, _Ret, _BindN>
: public _Bind_base<_Ret, _BindN>
{ // template class for objects returned by bind with no result_type
public:
_Bind(_BindN _B0)
: _Bind_base<_Ret, _BindN>(_B0)
{ // construct
}
};
template<class _Fty,
class _Ret,
class _BindN>
class _Bind_fty
: public _Wrap_result_type<_HAS_RESULT_TYPE(_Fty), _Fty>,
public _Bind_base<_Ret, _BindN>
{ // template class for objects returned by bind holding function objects
public:
_Bind_fty(_BindN _B0)
: _Bind_base<_Ret, _BindN>(_B0)
{ // construct
}
};
// TEMPLATE CLASS is_bind_expression SPECIALIZATIONS
template<class _Result_type,
class _Ret,
class _BindN>
struct is_bind_expression<
_Bind<_Result_type, _Ret, _BindN> >
{ // specialization to indicate a bind expression
static const bool value = true;
};
// TEMPLATE CLASS _Binder
template<bool _Expr,
int _Nx>
struct _Binder;
#define _CLASS_BARG0 _LIST_MAX(class _Barg)
#define _BARG0_B0 _LIST2_MAX(_Barg, _Bx)
#define _BARG0_B0_REF _LIST2_MAX(_Barg, && _Bx)
#define _BARG0_BARG1 _LIST_MAX(_Barg)
#define _BARG0_BARG1_REF _LIST15_MAX(_Barg, &)
#define _B0_B1 _LIST_MAX(_Bx)
template<>
struct _Binder<true, 0>
{ // bind argument to result of bind expression
template<class _Arg,
_CLASS_BARG0>
static typename _Arg::
_MyBind::template _Return<_BARG0_BARG1_REF>::_Type
_Get(_Arg _Ax, _BARG0_B0_REF)
{ // return result
return (_Ax(_B0_B1));
}
template<class _Arg,
_CLASS_BARG0>
struct _Ret
{ // describe type of result
typedef typename _Arg::
_MyBind::template _Return<_BARG0_BARG1>::_Type
_Type;
};
};
template<>
struct _Binder<false, 0>
{ // bind argument to passed value
template<class _Arg,
_CLASS_BARG0>
static _Arg& _Get(_Arg& _Val, _BARG0_B0_REF)
{ // return passed value
return (_Val);
}
template<class _Arg,
_CLASS_BARG0>
struct _Ret
{ // describe type of result
typedef _Arg& _Type;
};
};
// define _Binder<false, N>, _BindN:
#define _INCL_FILE_xxbind1
#include <xfwrap>
} // namespace tr1
#if _HAS_TR1_IMPORTS
using tr1::bad_function_call;
using tr1::bind;
using tr1::cref;
using tr1::function;
using tr1::is_bind_expression;
using tr1::is_placeholder;
using tr1::mem_fn;
using tr1::ref;
using tr1::reference_wrapper;
using tr1::result_of;
using tr1::swap;
namespace placeholders {
using namespace tr1::placeholders;
} // namespace placeholders
#endif /* _HAS_TR1_IMPORTS */
_STD_END
#endif /* _HAS_TR1 */
#pragma pop_macro("new")
#pragma warning(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _FUNCTIONAL_ */
/*
* Copyright (c) 1992-2009 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V5.20:0009 */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -