HandBooks Professional Java-C-Scrip-SQL part 75

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 75', 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ả | template called for_each_element to do just that. For the sake of argument the example shows two function objects to show the workings of for each element. include iostream include string include functional include boost tuple template typename Function void for_each_element const boost tuples null_type Function template typename Tuple typename Function void for_each_element Tuple t Function func func t. get_head for_each_element func struct print template typename T void operator const T t std cout t n template typename T struct print_type void operator const T t std cout t n template typename U void operator const U u int main typedef boost tuple short int long my_tuple boost tuple int short double nums 1 2 for_each_element nums print for_each_element nums print_type double The function for_each_element reuses the strategy from earlier examples by overloading the function with a version that accepts an argument of type null_type that signals the end of the tuple s elements to do nothing. Let s look at the function where the work is done. template typename Tuple typename Function void for_each_element Tuple t Function func func t. get_head for_each_element func The second template and function parameter specifies the function or function object to call with the tuple elements as argument. for_each_element first invokes the function object with the element returned from get_head. One way to think of it is that get_head returns the current element of the tuple. Then it recursively calls itself with the tail or remaining elements of the tuple. The next call extracts the head element and calls the function object with it and recurses again and so on. Eventually get_tail finds no more elements and returns an instance of null_type which ends the recursion by matching the non-recursive for_each_element overload. That s all there is to for_each_element Next the example illustrates two function objects that contain nice techniques for .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
TÀI LIỆU MỚI ĐĂNG
2    993    1    30-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.