libMesh
Loading...
Searching...
No Matches
Public Member Functions | List of all members
TransparentComparatorTest Class Reference
Inheritance diagram for TransparentComparatorTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (TransparentComparatorTest)
 
 CPPUNIT_TEST (testSet)
 
 CPPUNIT_TEST_SUITE_END ()
 
void testSet ()
 

Detailed Description

Definition at line 13 of file transparent_comparator.C.

Member Function Documentation

◆ CPPUNIT_TEST()

TransparentComparatorTest::CPPUNIT_TEST ( testSet  )

◆ CPPUNIT_TEST_SUITE_END()

TransparentComparatorTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

TransparentComparatorTest::LIBMESH_CPPUNIT_TEST_SUITE ( TransparentComparatorTest  )

◆ testSet()

void TransparentComparatorTest::testSet ( )
inline

Definition at line 20 of file transparent_comparator.C.

21 {
22 LOG_UNIT_TEST;
23
24 std::set<std::unique_ptr<int>, Utility::CompareUnderlying> s;
25 s.insert(std::make_unique<int>(1));
26 s.insert(std::make_unique<int>(2));
27 s.insert(std::make_unique<int>(3));
28 s.insert(std::make_unique<int>(3)); // Not a duplicate. This set does pointer comparisons, not value comparisons.
29
30 // Search for entry by pointer-to-int. This tests the desired
31 // behavior of the std::set comparison object.
32 int * first = s.begin()->get();
33 auto result = s.find(first);
34 CPPUNIT_ASSERT(result != s.end());
35 CPPUNIT_ASSERT(result->get() == first);
36
37 // Test set::count(). It should be using the same underlying
38 // machinery as std::set(find) but it's good to verify this.
39 CPPUNIT_ASSERT(s.count(first) == 1);
40
41 // Test that attempting to insert the same underlying pointer again fails. We simulate this by
42 // creating and moving from a standalone object.
43 auto four = std::make_unique<int>(4);
44
45 // The first insert() adds a non-nullptr underlying pointer to the
46 // set and leaves "four" with and underlying nullptr.
47 s.insert(std::move(four));
48 CPPUNIT_ASSERT(s.size() == 5);
49
50 // The second insert() adds a nullptr underlying pointer to the
51 // set and leaves "four" with and underlying nullptr.
52 s.insert(std::move(four));
53 CPPUNIT_ASSERT(s.size() == 6);
54
55 // The third insert() does not change the set because it tries to
56 // add a second nullptr underlying pointer to the set.
57 s.insert(std::move(four));
58 CPPUNIT_ASSERT(s.size() == 6);
59 }
Struct which defines a custom comparison object that can be used with std::sets of std::unique_ptrs.
Definition utility.h:486

The documentation for this class was generated from the following file: