tailieunhanh - 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 .

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