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

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 64', 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ả | std sort std for_each print_names std cout n std cout boost any_cast std string properties 0 .value n std cout boost any_cast int properties 1 .value n std cout boost any_cast double properties 2 .value n Notice that we didn t have to explicitly create the anys needed for property s constructor. That s because any s converting constructor isn t explicit. Although constructors taking one argument should typically be declared explicit any is an exception to the rule. Running the program gives us this output. Example of using any for storing properties. A B C Thirty something 30 In this example because the container was sorted we retrieved the properties by index and as we knew their respective types beforehand we didn t need a try catch block for the retrieval. When retrieving the value of an instance of any pass the any by const reference to any_cast if a failure indicates a real error. std string s boost any_cast std string a When a failure is not necessarily an error pass the any by pointer. std string ps boost any_cast std string a The different styles of getting the stored value differ not only in semantics but also how they return the stored value. If you pass a pointer argument you get a pointer to the stored value if you pass a const reference argument you get a copy of the value. If the value type is expensive to copy pass the any by pointer to avoid copying the value. There s More to any There are a few more member functions provided by any such as testing whether an instance of any is empty or not and swapping the values of two instances of any. The following example shows how to use them. include iostream include string include boost int main std cout Example of using any member functions n n boost any a1 100 boost any a2 std string 200 boost any a3 std cout a3 is if std cout not std cout empty n a2 try std string s boost any_cast std string a1 std cout al .

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.