tailieunhanh - HandBooks Professional Java-C-Scrip-SQL part 44
Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 44', 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ả | weak_ptr_unary std equal_to string string of using if it shared_ptr string sp it std cout sp n In the example a vector containing weak_ptrs is created. The most interesting line of code yes it s quite a long one is where we create a weak_ptr_unary_t for use with the find_if algorithm. vector weak_ptr string iterator it std find_if weak_ptr_unary std equal_to string string of using The function object is created by passing another function object std equal_to to the helper function weak_ptr_unary together with the string that is to be used for the matching. Because of the fact that weak_ptr_unary_t is compatible with adaptors it is compatible because it inherits from std unary_function we could compose any type of function object out of it. For instance we could have searched for the first string not matching of using vector weak_ptr string iterator it std find_if std not1 weak_ptr_unary std equal_to string string of using The Boost smart pointers were specifically designed to work well with the Standard Library. That makes it easy for us to create useful components that help us simplify the usage of these powerful smart pointers. Utilities such as weak_ptr_unary aren t needed all that often there are libraries that provide general binders that do a much better job of that than weakptr 51 These too are typically aware of smart pointer semantics which makes using them completely transparent to use. Two Idiomatic Ways of Creating a shared_ptr from a weak_ptr As you have seen when you have a weak_ptr that s observing some resource you ll eventually want to access that resource. To do so the weak_ptr must be converted to a shared_ptr because the weak_ptr alone does not allow direct access to the resource. There are two ways of creating a shared_ptr from a weak_ptr Either pass the weak_ptr to the constructor of shared_ptr or call the weak_ptr member function lock which returns a shared_ptr. Which to choose depends on .
đang nạp các trang xem trước