//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // template struct owner_less; // // template // struct owner_less > // : binary_function, shared_ptr, bool> // { // typedef bool result_type; // bool operator()(shared_ptr const&, shared_ptr const&) const; // bool operator()(shared_ptr const&, weak_ptr const&) const; // bool operator()(weak_ptr const&, shared_ptr const&) const; // }; // // template // struct owner_less > // : binary_function, weak_ptr, bool> // { // typedef bool result_type; // bool operator()(weak_ptr const&, weak_ptr const&) const; // bool operator()(shared_ptr const&, weak_ptr const&) const; // bool operator()(weak_ptr const&, shared_ptr const&) const; // }; #include #include int main() { const std::shared_ptr p1(new int); const std::shared_ptr p2 = p1; const std::shared_ptr p3(new int); const std::weak_ptr w1(p1); const std::weak_ptr w2(p2); const std::weak_ptr w3(p3); { typedef std::owner_less > CS; CS cs; assert(!cs(p1, p2)); assert(!cs(p2, p1)); assert(cs(p1 ,p3) || cs(p3, p1)); assert(cs(p3, p1) == cs(p3, p2)); assert(!cs(p1, w2)); assert(!cs(p2, w1)); assert(cs(p1, w3) || cs(p3, w1)); assert(cs(p3, w1) == cs(p3, w2)); } { typedef std::owner_less > CS; CS cs; assert(!cs(w1, w2)); assert(!cs(w2, w1)); assert(cs(w1, w3) || cs(w3, w1)); assert(cs(w3, w1) == cs(w3, w2)); assert(!cs(w1, p2)); assert(!cs(w2, p1)); assert(cs(w1, p3) || cs(w3, p1)); assert(cs(w3, p1) == cs(w3, p2)); } }