TAILIEUCHUNG - HandBooks Professional Java-C-Scrip-SQL part 81

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 81', 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ả | Or if we had been a bit more responsible and created terse typedef s for the vector and map std for_each boost bind print std cout boost bind vec_type size boost bind map_type value_type second _1 That s a bit easier to parse but it s still a bit too much. Although there may be some good arguments for using the bind version I think that the point is clearbinders are incredibly useful tools that should be used responsibly where they add value. This is very very common when using the Standard Library containers and algorithms. But when things get too complicated do it the old fashioned way. Let Binders Handle State There are several options available to use when creating a function object like print_size. The version that we created in the previous section stored a reference to a std ostream and used that ostream to print the return value of size for the member second on the map_type value_type argument. Here s the original print_size again class print_size std ostream os_ typedef std map std string std vector int map_type public print_size std ostream os os_ os void operator const map_type value_type x const os_ n An important observation for this class is that is has state through the stored std ostream. We could remove the state by adding the ostream as an argument to the function call operator. This would mean that the function object becomes stateless. class print_size typedef std map std string std vector int map_type public typedef void result_type result_type operator std ostream os const map_type value_type x const os n Note that this version of print_size is well behaved when used with bind through the addition of the result_type typedef. This relieves users from having to explicitly state the return type of the function object when using bind. In this new version of print_size users need to pass an ostream as an argument when invoking it. That s easy when using binders. Rewriting the example from the previous .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.