Skip to content

Commit 4418f25

Browse files
committed
Rename observer_ptr::lock into observer_ptr::get
1 parent 55d73ae commit 4418f25

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

include/oup/observable_unique_ptr.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class observer_ptr : private std::weak_ptr<T> {
359359
* make sure that the owning observable_unique_ptr will not be reset until
360360
* you are done using the raw pointer.
361361
*/
362-
T* lock() const noexcept {
362+
T* get() const noexcept {
363363
return std::weak_ptr<T>::lock().get();
364364
}
365365

@@ -401,12 +401,12 @@ bool operator!= (std::nullptr_t, const observer_ptr<T>& value) noexcept {
401401

402402
template<typename T, typename U>
403403
bool operator== (const observer_ptr<T>& first, const observer_ptr<U>& second) noexcept {
404-
return first.lock() == second.lock();
404+
return first.get() == second.get();
405405
}
406406

407407
template<typename T, typename U>
408408
bool operator!= (const observer_ptr<T>& first, const observer_ptr<U>& second) noexcept {
409-
return first.lock() != second.lock();
409+
return first.get() != second.get();
410410
}
411411

412412
}

tests/runtime_tests.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ TEST_CASE("observer default constructor", "[observer_construction]") {
546546
{
547547
test_optr ptr{};
548548
REQUIRE(instances == 0);
549-
REQUIRE(ptr.lock() == nullptr);
549+
REQUIRE(ptr.get() == nullptr);
550550
REQUIRE(ptr.expired() == true);
551551
}
552552

@@ -557,7 +557,7 @@ TEST_CASE("observer nullptr constructor", "[observer_construction]") {
557557
{
558558
test_optr ptr{nullptr};
559559
REQUIRE(instances == 0);
560-
REQUIRE(ptr.lock() == nullptr);
560+
REQUIRE(ptr.get() == nullptr);
561561
REQUIRE(ptr.expired() == true);
562562
}
563563

@@ -571,7 +571,7 @@ TEST_CASE("observer move constructor", "[observer_construction]") {
571571
{
572572
test_optr ptr(std::move(ptr_orig));
573573
REQUIRE(instances == 1);
574-
REQUIRE(ptr.lock() != nullptr);
574+
REQUIRE(ptr.get() != nullptr);
575575
REQUIRE(ptr.expired() == false);
576576
}
577577

@@ -586,7 +586,7 @@ TEST_CASE("observer acquiring constructor", "[observer_construction]") {
586586
test_ptr ptr_owner{new test_object};
587587
test_optr ptr{ptr_owner};
588588
REQUIRE(instances == 1);
589-
REQUIRE(ptr.lock() != nullptr);
589+
REQUIRE(ptr.get() != nullptr);
590590
REQUIRE(ptr.expired() == false);
591591
}
592592

@@ -598,7 +598,7 @@ TEST_CASE("observer acquiring constructor derived", "[observer_construction]") {
598598
test_ptr_derived ptr_owner{new test_object_derived};
599599
test_optr ptr{ptr_owner};
600600
REQUIRE(instances == 1);
601-
REQUIRE(ptr.lock() != nullptr);
601+
REQUIRE(ptr.get() != nullptr);
602602
REQUIRE(ptr.expired() == false);
603603
}
604604

@@ -613,13 +613,13 @@ TEST_CASE("observer implicit copy conversion constructor", "[observer_constructi
613613
test_optr ptr(ptr_orig);
614614
REQUIRE(instances == 1);
615615
REQUIRE(instances_derived == 1);
616-
REQUIRE(ptr.lock() != nullptr);
616+
REQUIRE(ptr.get() != nullptr);
617617
REQUIRE(ptr.expired() == false);
618618
}
619619

620620
REQUIRE(instances == 1);
621621
REQUIRE(instances_derived == 1);
622-
REQUIRE(ptr_orig.lock() != nullptr);
622+
REQUIRE(ptr_orig.get() != nullptr);
623623
REQUIRE(ptr_orig.expired() == false);
624624
}
625625

@@ -635,13 +635,13 @@ TEST_CASE("observer implicit move conversion constructor", "[observer_constructi
635635
test_optr ptr(std::move(ptr_orig));
636636
REQUIRE(instances == 1);
637637
REQUIRE(instances_derived == 1);
638-
REQUIRE(ptr.lock() != nullptr);
638+
REQUIRE(ptr.get() != nullptr);
639639
REQUIRE(ptr.expired() == false);
640640
}
641641

642642
REQUIRE(instances == 1);
643643
REQUIRE(instances_derived == 1);
644-
REQUIRE(ptr_orig.lock() == nullptr);
644+
REQUIRE(ptr_orig.get() == nullptr);
645645
REQUIRE(ptr_orig.expired() == true);
646646
}
647647

@@ -656,12 +656,12 @@ TEST_CASE("observer expiring", "[observer_utility]") {
656656
test_ptr ptr_owner{new test_object};
657657
ptr = ptr_owner;
658658
REQUIRE(instances == 1);
659-
REQUIRE(ptr.lock() != nullptr);
659+
REQUIRE(ptr.get() != nullptr);
660660
REQUIRE(ptr.expired() == false);
661661
}
662662

663663
REQUIRE(instances == 0);
664-
REQUIRE(ptr.lock() == nullptr);
664+
REQUIRE(ptr.get() == nullptr);
665665
REQUIRE(ptr.expired() == true);
666666
}
667667

@@ -671,7 +671,7 @@ TEST_CASE("observer reset to null", "[observer_utility]") {
671671
test_optr ptr(ptr_owner);
672672
ptr.reset();
673673
REQUIRE(instances == 1);
674-
REQUIRE(ptr.lock() == nullptr);
674+
REQUIRE(ptr.get() == nullptr);
675675
REQUIRE(ptr.expired() == true);
676676
}
677677

@@ -685,8 +685,8 @@ TEST_CASE("observer swap no instance", "[observer_utility]") {
685685
test_optr ptr;
686686
ptr.swap(ptr_orig);
687687
REQUIRE(instances == 0);
688-
REQUIRE(ptr_orig.lock() == nullptr);
689-
REQUIRE(ptr.lock() == nullptr);
688+
REQUIRE(ptr_orig.get() == nullptr);
689+
REQUIRE(ptr.get() == nullptr);
690690
REQUIRE(ptr_orig.expired() == true);
691691
REQUIRE(ptr.expired() == true);
692692
}
@@ -701,8 +701,8 @@ TEST_CASE("observer swap one instance", "[observer_utility]") {
701701
test_optr ptr;
702702
ptr.swap(ptr_orig);
703703
REQUIRE(instances == 1);
704-
REQUIRE(ptr_orig.lock() == nullptr);
705-
REQUIRE(ptr.lock() != nullptr);
704+
REQUIRE(ptr_orig.get() == nullptr);
705+
REQUIRE(ptr.get() != nullptr);
706706
REQUIRE(ptr_orig.expired() == true);
707707
REQUIRE(ptr.expired() == false);
708708
}
@@ -717,8 +717,8 @@ TEST_CASE("observer swap two same instance", "[observer_utility]") {
717717
test_optr ptr(ptr_owner);
718718
ptr.swap(ptr_orig);
719719
REQUIRE(instances == 1);
720-
REQUIRE(ptr_orig.lock() == ptr_owner.get());
721-
REQUIRE(ptr.lock() == ptr_owner.get());
720+
REQUIRE(ptr_orig.get() == ptr_owner.get());
721+
REQUIRE(ptr.get() == ptr_owner.get());
722722
REQUIRE(ptr_orig.expired() == false);
723723
REQUIRE(ptr.expired() == false);
724724
}
@@ -734,8 +734,8 @@ TEST_CASE("observer swap two different instances", "[observer_utility]") {
734734
test_optr ptr(ptr_owner2);
735735
ptr.swap(ptr_orig);
736736
REQUIRE(instances == 2);
737-
REQUIRE(ptr_orig.lock() == ptr_owner2.get());
738-
REQUIRE(ptr.lock() == ptr_owner1.get());
737+
REQUIRE(ptr_orig.get() == ptr_owner2.get());
738+
REQUIRE(ptr.get() == ptr_owner1.get());
739739
REQUIRE(ptr_orig.expired() == false);
740740
REQUIRE(ptr.expired() == false);
741741
}

0 commit comments

Comments
 (0)