tailieunhanh - HandBooks Professional Java-C-Scrip-SQL part 86

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 86', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 2 1 add_prev int ap std transform bind var ap _1 The problem is the call to transform. std transform bind var ap _1 When the binder is instantiated the mechanism for return type deduction kicks in. .and fails. Thus the program does not compile and you must explicitly tell bind the return type like so std transform bind int var ap _1 This is a shorthand notation for the general form of explicitly setting the return types for lambda expression and it s the equivalent of this code. std transform ret int bind int var ap _1 This problem isn t new it s virtually the same that applies for function objects used by the Standard Library algorithms. There the solution is to add typedefs that state the return type and argument type s of the function objects. The Standard Library even provides helper classes for accomplishing this through the class templates unary_function and binary_functionour example class add_prev could become a compliant function object by either defining the required typedefs argument_type and result_type for unary function objects first_argument_type second_argument_type and result_type for binary function objects or inheriting from unary function binary function. template typename T class add_prev public std unary_function T T Is this good enough for lambda expressions too Can we simply reuse this scheme and thus our existing function objects too Alas the answer is no. There is a problem with this typede f approach What happens when the result type or the argument type s is dependent on a template parameter to a parameterized function call operator Or when there are several overloaded function call operators Had there been language support for template typedefs much of the problem would be solved but currently that s not the case. That s why requires a different approach through a nested parameterized .

TÀI LIỆU LIÊN QUAN
10    158    1
6    184    1
7    162    1
5    157    1
6    160    1
6    152    1
6    150    1
6    206    1
7    154    1