C++ function??bind???lamda????
???????????? ???????[ 2015/1/16 11:16:43 ] ????????C++ ??????? NET
	??????????C++0x??е??????????????????C++0x????????lambda?????? function?????bind????????????????????????????????????????????????е?????????????????????????????????????????????????????closure?????????????????????lambda?????????????????????wikipedia??????????????closure????壺
	????A closure (also lexical closure?? function closure or function value) is a function together with
	????a referencing environment for the non-local variables of that function.
	?????????????????closure????????????????????????????????????????????????????????????closure??????????????巶Χ????????????????????non-local vriables?????????????????????????closure?????????????????????????????????function?? bind??lambda????????????????????????????????????????и????????????????????????????????????????
	????1. function
	???????????????C++?У??????????????????????????????????????????????????????????????????????opetator()???????C++98?е?functor)??C++0x?У????????????std::function????std::function???????C++?????е?????????????????????????????????????????????????壬???????????????????????????????function??????????
	#include < functional>
	std::function< size_t (const char*) > print_func;
	/// normal function -> std::function object
	size_t CPrint(const char*) { ... }
	print_func = CPrint;
	print_func("hello world"):
	/// functor -> std::function object
	class CxxPrint
	{
	public:
	size_t operator()(const char*) { ... }
	};
	CxxPrint p;
	print_func = p;
	print_func("hello world");
	????????????????У??????????????????????functor??????????std::function????????????????????????á???????C++?е???????嶼?????????????????á????std::function?????????????????????????????????????????壬??????y?????????????????????std::function??????÷????????????????Щ??ù????е????????
	??????1?????????????????std::function??????????????????????
	????a. ??????std::function??????????????????????????
	????b. ???????????????????std::function????????????????е???????????????????void??std::function????????????????
	??????2??std::function???????refer to????1?????????????????????
	??????3??std::function object????????????????????????????????????????????????????????
	????2. bind
	????bind????????????????????????????????????Щ???????????е??????????????μ???????壬???????????????????ù????????????á?C++98?У???????????bind1st??bind2nd?????????????????functor????????????????????????????????????????????????????bind1st??bind2nd????????????C++0x?У?????std::bind??????????????????????????????????Щ???????????????????????????bind??????????????????????????bind1st??bind2nd???????????????C++0x?в???????bind1st??bind2nd???????deprecated?????????????????????????bind???÷???
	#include < functional>
	int Func(int x?? int y);
	auto bf1 = std::bind(Func?? 10?? std::placeholders::_1);
	bf1(20); ///< same as Func(10?? 20)
	class A
	{
	public:
	int Func(int x?? int y);
	};
	A a;
	auto bf2 = std::bind(&A::Func?? a?? std::placeholders::_1?? std::placeholders::_2);
	bf2(10?? 20); ///< same as a.Func(10?? 20)
	std::function< int(int)> bf3 = std::bind(&A::Func?? a?? std::placeholders::_1?? 100);
	bf3(10); ///< same as a.Func(10?? 100)
	??????????????У?bf1??????????????????????????????????10????????????μ???????????????????; bf2???????????????????????????????????????????????μ????????; bf3?????????????????????????????????????????μ?std::function???????????????????????????????????bind????????Щ????
	??????1??bind???????????????????????????????????????????????pass-by-value??
	??????2????????????????????????std::placeholders???????_1????????ε?????placeholder??pass-by-reference??
	??????3??bind??????????????壬??????????std::function????
	??????4???????????????????????????????????????????????????????Щ??????????
	??????5?????this?????????????????????
??????
 
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44 
					
 
			 
								 
								 
								 
								 
								 
								 
								 
								 
								 
								 
				 sales@spasvo.com
sales@spasvo.com