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

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 67', 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ả | Here is how the extractor function object that operates on a container of anys works populating a new container with a certain type collected from the source container. Get all ints in vec std list int lst std for_each make_extractor int std back_inserter lst std cout Found ints in vec n n Let s clear the contents of the container vec and add some new values. std string This is a string 42 Now let s try the predicates that we created. First we use the two predicates that indicate whether an any contains a string or an int respectively. if is_string vec 0 std cout Found me a string n if is_int vec 1 std cout Found me an int n As we concluded earlier defining predicates for every type we are ever interested in is tedious and utterly unnecessary when we can use the language to our advantage in a straightforward manner. if contains double vec 2 std cout The generic tool is sweeter found me a double n Running this example gives you this output. Example of using predicates and the function object any_counter There are 10 non-empty any s in vec Found 10 ints in vec Found me a string Found me an int The generic tool is sweeter found me a double Small and simple tools like these have proven to be very useful. Of course this is not only true for any it s a property of the design of the Standard Library containers and algorithms. The examples show how to take advantage of function composition together with any. Providing filtering counting operations on certain types and so forth are powerful ways of hiding implementation details and simplifying the usage of any. Complying with the Requirements of Standard Library Adapters If you found the predicate contains useful you may have noticed that it is not quite all it can be. There is no way to use it together with the Standard Library adapters. The following example is slightly outside the scope of this chapter but because any fits so well with .

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.