llvm.org GIT mirror llvm / e8f9913
Add partial implementation of std::to_address() as llvm::to_address() Summary: Following on from the review for D58088, this patch provides the prerequisite to_address() implementation that's needed to have pointer_iterator support unique_ptr. The late bound return should be removed once we move to C++14 to better align with the C++20 declaration. Also, this implementation can be removed once we move to C++20 where it's defined as std::to_addres() The std::pointer_traits<>::to_address(p) variations of these overloads has not been implemented. Reviewers: dblaikie, paquette Reviewed By: dblaikie Subscribers: dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58421 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354491 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Sanders 5 months ago
2 changed file(s) with 36 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
15751575 return true;
15761576 }
15771577
1578 /// Returns a raw pointer that represents the same address as the argument.
1579 ///
1580 /// The late bound return should be removed once we move to C++14 to better
1581 /// align with the C++20 declaration. Also, this implementation can be removed
1582 /// once we move to C++20 where it's defined as std::to_addres()
1583 ///
1584 /// The std::pointer_traits<>::to_address(p) variations of these overloads has
1585 /// not been implemented.
1586 template auto to_address(const Ptr &P) -> decltype(P.operator->()) {
1587 return P.operator->();
1588 }
1589 template constexpr T *to_address(T *P) { return P; }
1590
15781591 } // end namespace llvm
15791592
15801593 #endif // LLVM_ADT_STLEXTRAS_H
445445 EXPECT_FALSE(is_splat(V));
446446 }
447447
448 TEST(STLExtrasTest, to_address) {
449 int *V1 = new int;
450 EXPECT_EQ(V1, to_address(V1));
451
452 // Check fancy pointer overload for unique_ptr
453 std::unique_ptr V2 = make_unique(0);
454 EXPECT_EQ(V2.get(), to_address(V2));
455
456 V2.reset(V1);
457 EXPECT_EQ(V1, to_address(V2));
458 V2.release();
459
460 // Check fancy pointer overload for shared_ptr
461 std::shared_ptr V3 = std::make_shared(0);
462 std::shared_ptr V4 = V3;
463 EXPECT_EQ(V3.get(), V4.get());
464 EXPECT_EQ(V3.get(), to_address(V3));
465 EXPECT_EQ(V4.get(), to_address(V4));
466
467 V3.reset(V1);
468 EXPECT_EQ(V1, to_address(V3));
469 }
470
448471 } // namespace