// xvbind1 header for variadic templates
#ifndef _XVBIND_
#define _XVBIND_

	// TEMPLATE CLASS is_bind_expression
template<bool _Forced,
	class _Ret,
	class _Fun,
	class... _Types>
	struct _Bind;
template<bool _Forced,
	class _Ret,
	class _Fun,
	class... _Types>
	struct is_bind_expression<_Bind<_Forced, _Ret, _Fun, _Types...> >
	{	// specialization to indicate a bind expression
	static const bool value = true;
	};

	// TEMPLATE CLASS _Is_reference_wrapper
template <class _Barg>
	struct _Is_reference_wrapper
		: false_type {;
		}
template <class _Barg>
	struct _Is_reference_wrapper<reference_wrapper<_Barg> >
		: true_type {;
		}

	// TEMPLATE CLASS _Classify_barg
enum _Barg_type
	{
	_Reference_wrapper,
	_Placeholder,
	_Bind_expression,
	_UDT
	};

template <class _Barg>
	struct _Classify_barg
		: integral_constant<_Barg_type,
			_Is_reference_wrapper<_Barg>::value ? _Reference_wrapper
			: 0 < is_placeholder<_Barg>::value ? _Placeholder
			: is_bind_expression<_Barg>::value ? _Bind_expression
			: _UDT> {;
			}

	// TEMPLATE CLASS _Fixarg_ret_base
template <_Barg_type, class _Barg, class _Ftuple>
	struct _Fixarg_ret_base;
template <class _Barg, class _Ftuple>
	struct _Fixarg_ret_base<_Reference_wrapper, _Barg, _Ftuple>
	{	// return type for reference_wrapper
	typedef typename add_reference<typename _Barg::type>::type _Type;
	};
template <class _Barg, class _Ftuple>
	struct _Fixarg_ret_base<_Placeholder, _Barg, _Ftuple>
	{	// return type for placeholder
	typedef
		typename add_reference<
		typename tuple_element<is_placeholder<_Barg>::value - 1,
			_Ftuple>::type>::type _Type;
	};
template <class _Barg, class _Ftuple>
	struct _Fixarg_ret_base<_UDT, _Barg, _Ftuple>
	{	// return type for plain user-defined type
	typedef typename _Result_of<_Barg, _Ftuple>::_Type _Type;
	};

	// TEMPLATE CLASS _Fixarg_ret
template <class _Barg, class _Ftuple>
	struct _Fixarg_ret
	: _Fixarg_ret_base<
		_Classify_barg<typename _Remove_reference<_Barg>::_Type>::value,
		typename _Remove_reference<_Barg>::_Type,
		_Ftuple>
	{
	};

	// TEMPLATE CLASS _Do_call_ret
template <bool _Forced,
	class _Ret,
	class _Fun,
	class _Btuple,
	class _Ftuple,
	class _Indexes>
	struct _Do_call_ret;

template <bool _Forced,
	class _Ret,
	class _Fun,
	class _Btuple,
	class _Ftuple,
	size_t... _Bindexes>
	struct _Do_call_ret<
		_Forced, _Ret, _Fun, _Btuple, _Ftuple, _Arg_idx<_Bindexes...> >
	{	// generate return type from simulated call
	typedef
		typename result_of<
		_Fun(
			typename _Fixarg_ret<
				typename tuple_element<_Bindexes, _Btuple>::_Rtype,
				_Ftuple
			>::_Type...
		)
		>::type
	_Type;
	};
template <class _Ret,
	class _Fun,
	class _Btuple,
	class _Ftuple,
	size_t... _Bindexes>
	struct _Do_call_ret<
		true, _Ret, _Fun, _Btuple, _Ftuple, _Arg_idx<_Bindexes...> >
	{	// use forced return type
	typedef _Ret _Type;
	};

	// TEMPLATE CLASS _Add_result_type
template<bool _Forced,
	bool _Fun_has_result_type,
	class _Ret,
	class _Fun>
	struct _Add_result_type
	{	// do not define result_type
	};
template<bool _Fun_has_result_type,
	class _Ret,
	class _Fun>
	struct _Add_result_type<true, _Fun_has_result_type, _Ret, _Fun>
	{	// define reesult_type as forced type
	typedef _Ret result_type;
	};
template<class _Ret,
	class _Fun>
	struct _Add_result_type<false, true, _Ret, _Fun>
	{	// define result type as nested in _Fun
	typedef typename _Fun::result_type result_type;
	};

	// TEMPLATE CLASS _Bind
template<bool _Forced,
	class _Ret,
	class _Fun,
	class... _Types>
	class _Bind
		: public _Add_result_type<_Forced, _HAS_RESULT_TYPE(_Fun),
			_Ret, _Fun>
	{	// wrap bound function and arguments
public:
	typedef tuple<_Types...> _Bargs;

	explicit _Bind(const _Fun& _Fx, const _Types&... _Args)
		: _Myfun(_Fx), _Mybargs(_Args...)
		{	// construct fron functor and arguments
		}

	template<class... _Ftypes>
		typename
		_Do_call_ret<_Forced, _Ret, _Fun, tuple<_Types...>,
			tuple<_Ftypes&...>,
			typename _Make_arg_idx<_Types...>::type>::_Type
		operator()(_Ftypes&&... _Fargs)
		{	// evaluate the called function
		return (_Do_call(tie(_Fargs...),
			typename _Make_arg_idx<_Types...>::type()));
		}

	template<class... _Ftypes>
		typename
		_Do_call_ret<_Forced, _Ret, _Fun, tuple<_Types...>,
			tuple<_Ftypes&...>,
			typename _Make_arg_idx<_Types...>::type>::_Type
		operator()(_Ftypes&&... _Fargs) const
		{	// evaluate the called function
		return (_Do_call(tie(_Fargs...),
			typename _Make_arg_idx<_Types...>::type()));
		}

	template<class... _Ftypes,
		size_t... _Bindexes>
		typename
		_Do_call_ret<_Forced, _Ret, _Fun, tuple<_Types...>,
			tuple<_Ftypes&...>,
			_Arg_idx<_Bindexes...> >::_Type
		_Do_call(tuple<_Ftypes&...> _Myfargs,
			_Arg_idx<_Bindexes...>)
		{	// call the stored functor with bound arguments
		return (_Myfun(_Fixarg(_Mybargs, _Myfargs,
			get<_Bindexes>(_Mybargs))...));
		}

	template<class _Barg,
		class... _Btypes,
		class... _Ftypes>
		typename enable_if<_Is_reference_wrapper<_Barg>::value,
			typename add_reference<typename _Barg::type>::type>::type
		_Fixarg(tuple<_Btypes...>& _Mybargs,
			tuple<_Ftypes...>& _Myfargs,
			_Barg& _Arg)
		{	// convert a reference_wrapper argument
		return (_Arg.get());
		}
	
	template<class _Barg,
		class... _Btypes,
		class... _Ftypes>
		typename enable_if<0 < is_placeholder<_Barg>::value,
			typename add_reference<
			typename tuple_element<is_placeholder<_Barg>::value - 1,
				tuple<_Ftypes...> >::type>::type>::type
		_Fixarg(tuple<_Btypes...>& _Mybargs,
			tuple<_Ftypes...>& _Myfargs,
			_Barg& _Arg)
		{	// convert a placeholder argument
		const int _Nx = is_placeholder<_Barg>::value - 1;
		return (get<_Nx>(_Myfargs));
		}

	template<class _Barg,
		class... _Btypes,
		class... _Ftypes>
		typename enable_if<is_bind_expression<_Barg>::value,
			typename _Barg::result_type>::type
		_Fixarg(tuple<_Btypes...>& _Mybargs,
			tuple<_Ftypes...>& _Myfargs,
			_Barg& _Arg)
		{	// convert a nested _Bind argument
		return (_Do_bind_call<typename _Copy_cv<_Barg, _Fun>::_Type>(
			_Mybargs,
			typename _Make_arg_idx<_Types...>::type(),
			_Arg));
		}

	template<class _Barg,
		size_t... _Bindexes,
		class... _Btypes>
		typename _Barg::result_type
		_Do_bind_call(tuple<_Btypes...>& _Mybargs,
			_Arg_idx<_Bindexes...>,
			_Barg& _Arg)
		{	// call nested _Bind argument
		return (_Arg(get<_Bindexes>(_Mybargs)...));
		}

	template<class _Barg,
		class... _Btypes,
		class... _Ftypes>
		typename enable_if<!is_bind_expression<_Barg>::value
				&& !is_placeholder<_Barg>::value
				&& !_Is_reference_wrapper<_Barg>::value,
			typename _Copy_cv<_Barg, _Fun>::_Type>::type
		_Fixarg(tuple<_Btypes...>& _Mybargs,
			tuple<_Ftypes...>& _Myfargs,
			_Barg& _Arg)
		{	// convert a plain argument
		return (_Arg);
		}

private:
	_Fun _Myfun;	// the stored functor
	tuple<_Types...> _Mybargs;	// the bound arguments
	};

	// TEMPLATE CLASS _Pmd_wrap
template<class _Pmd_t,
	class _Rx,
	class _Farg0>
	struct _Pmd_wrap
	{	// wrap a pointer to member data
//	typedef _Rx _Farg0::* _Pmd_t;

	_Pmd_wrap(const _Pmd_t& _Pmd)
		: _Mypmd(_Pmd)
		{	// construct with wrapped pointer
		}

	_Rx& operator()(_Farg0& _Fnobj) const
		{	// get the data
		return (_Fnobj.*_Mypmd);
		}

	const _Rx& operator()(const _Farg0& _Fnobj) const
		{	// get the data
		return (_Fnobj.*_Mypmd);
		}

	volatile _Rx& operator()(volatile _Farg0& _Fnobj) const
		{	// get the data
		return (_Fnobj.*_Mypmd);
		}

	const volatile _Rx& operator()(const volatile _Farg0& _Fnobj) const
		{	// get the data
		return (_Fnobj.*_Mypmd);
		}

private:
	_Pmd_t _Mypmd;
	};

template<class _Pmd_t,
	class _Rx,
	class _Farg0,
	class _Arg0,
	class... _Rest>
	struct _Result_of<_Pmd_wrap<_Pmd_t, _Rx, _Farg0>, _Arg0, _Rest...>
	{	// template to determine result of call operation
	typedef typename _Copy_cv<_Rx, _Arg0>::_Type _Type;
	};

template<class _Pmd_t,
	class _Rx,
	class _Farg0,
	class _Arg0,
	class... _Rest>
	struct _Result_of<_Pmd_wrap<_Pmd_t, _Rx, _Farg0>,
		reference_wrapper<_Arg0>&, _Rest...>
	{	// template to determine result of call operation
	typedef typename _Copy_cv<_Rx, _Arg0>::_Type _Type;
	};

	// TEMPLATE CLASS _Pmf_wrap
template<class _Pmf_t,
	class _Rx,
	class _Farg0,
	class... _Ftypes>
	struct _Pmf_wrap
	{	// wrap a pointer to member function
//	typedef _Rx (_Farg0::* _Pmf_t)(_Ftypes...);

	_Pmf_wrap(const _Pmf_t& _Pmf)
		: _Mypmf(_Pmf)
		{	// construct with wrapped pointer
		}

	_Rx operator()(_Farg0& _Fnobj, _Ftypes... _Fargs) const
		{	// call the function
		return ((_Fnobj.*_Mypmf)(_Fargs...));
		}

	_Rx operator()(const _Farg0& _Fnobj, _Ftypes... _Fargs) const
		{	// call the function
		return ((_Fnobj.*_Mypmf)(_Fargs...));
		}

	_Rx operator()(_Farg0 *_Pfnobj, _Ftypes... _Fargs) const
		{	// call the function
		return ((_Pfnobj->*_Mypmf)(_Fargs...));
		}

	_Rx operator()(const _Farg0 *_Pfnobj, _Ftypes... _Fargs) const
		{	// call the function
		return ((_Pfnobj->*_Mypmf)(_Fargs...));
		}

	template<class _Wrapper>
		_Rx operator()(_Wrapper& _Ptr, _Ftypes... _Fargs) const
		{	// call the function
		return (((*_Ptr).*_Mypmf)(_Fargs...));
		}

	template<class _Wrapper>
		_Rx operator()(const _Wrapper& _Ptr, _Ftypes... _Fargs) const
		{	// call the function
		return (((*_Ptr).*_Mypmf)(_Fargs...));
		}

private:
	_Pmf_t _Mypmf;
	};

	// TEMPLATE FUNCTION bind (implicit return type)
template<class _Fun,
	class... _Types> inline
	_Bind<false, void, _Fun, _Types...>
		bind(const _Fun& _Fx, const _Types&... _Args)
	{	// bind a function object
	return (_Bind<false, void, _Fun, _Types...>(
		_Fx, _Args...));
	}

template<class _Rx,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Rx, _Rx (* const)(_Ftypes...), _Types...>
		bind(_Rx (*_Pfx)(_Ftypes...), const _Types&... _Args)
	{	// bind a function pointer
	return (_Bind<true, _Rx, _Rx (* const)(_Ftypes...), _Types...>(
		_Pfx, _Args...));
	}

template<class _Rx,
	class _Farg0,
	class... _Types> inline
	_Bind<false, void, _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>,
		_Types...>
		bind(_Rx _Farg0::* const _Pmd, const _Types&... _Args)
	{	// bind a wrapped member object pointer
	return (_Bind<false, void,
		_Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>, _Types...>(
		_Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>(_Pmd), _Args...));
	}

template<class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...),
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...),
			const _Types&... _Args)
	{	// bind a wrapped member function pointer
	return (_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...),
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...),
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

template<class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...) const,
			const _Types&... _Args)
	{	// bind a wrapped const member function pointer
	return (_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const,
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

template<class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...) volatile,
			const _Types&... _Args)
	{	// bind a wrapped volatile member function pointer
	return (_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) volatile,
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

template<class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...) const volatile,
			const _Types&... _Args)
	{	// bind a wrapped const volatile member function pointer
	return (_Bind<true, _Rx,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const volatile,
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

	// TEMPLATE FUNCTION bind (explicit return type)
template<class _Ret,
	class _Fun,
	class... _Types> inline
	_Bind<true, _Ret, _Fun, _Types...>
		bind(const _Fun& _Fx, const _Types&... _Args)
	{	// bind a function object
	return (_Bind<true, _Ret, _Fun, _Types...>(
		_Fx, _Args...));
	}

template<class _Ret,
	class _Rx,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Ret, _Rx (* const)(_Ftypes...), _Types...>
		bind(_Rx (*_Pfx)(_Ftypes...), const _Types&... _Args)
	{	// bind a function pointer
	return (_Bind<true, _Ret, _Rx (* const)(_Ftypes...), _Types...>(
		_Pfx, _Args...));
	}

template<class _Ret,
	class _Rx,
	class _Farg0,
	class... _Types> inline
	_Bind<true, _Ret, _Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>,
		_Types...>
		bind(_Rx _Farg0::* const _Pmd, const _Types&... _Args)
	{	// bind a wrapped member object pointer
	return (_Bind<true, _Ret,
		_Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>, _Types...>(
		_Pmd_wrap<_Rx _Farg0::*, _Rx, _Farg0>(_Pmd), _Args...));
	}

template<class _Ret,
	class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...),
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...),
			const _Types&... _Args)
	{	// bind a wrapped member function pointer
	return (_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...),
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...),
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

template<class _Ret,
	class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...) const,
			const _Types&... _Args)
	{	// bind a wrapped const member function pointer
	return (_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const,
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

template<class _Ret,
	class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...) volatile,
			const _Types&... _Args)
	{	// bind a wrapped volatile member function pointer
	return (_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) volatile,
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

template<class _Ret,
	class _Rx,
	class _Farg0,
	class... _Ftypes,
	class... _Types> inline
	_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>
		bind(_Rx (_Farg0::* const _Pmf)(_Ftypes...) const volatile,
			const _Types&... _Args)
	{	// bind a wrapped const volatile member function pointer
	return (_Bind<true, _Ret,
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const volatile,
			_Rx, _Farg0, _Ftypes...>,
		_Types...>(
		_Pmf_wrap<_Rx (_Farg0::*)(_Ftypes...) const volatile,
			_Rx, _Farg0, _Ftypes...>(_Pmf),
		_Args...));
	}

	// PLACEHOLDER ARGUMENTS
		namespace placeholders {	// placeholders
static _Ph<1> _1;
static _Ph<2> _2;
static _Ph<3> _3;
static _Ph<4> _4;
static _Ph<5> _5;
static _Ph<6> _6;
static _Ph<7> _7;
static _Ph<8> _8;
static _Ph<9> _9;
static _Ph<10> _10;
static _Ph<11> _11;
static _Ph<12> _12;
static _Ph<13> _13;
static _Ph<14> _14;
static _Ph<15> _15;
static _Ph<16> _16;
static _Ph<17> _17;
static _Ph<18> _18;
static _Ph<19> _19;
static _Ph<20> _20;
		}	// namespace placeholders
#endif /* _XVBIND_ */

/*
 * Copyright (c) 1992-2010 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.30:0009 */
