File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,18 @@ template<typename T>
18
18
class singleton {
19
19
20
20
public:
21
- singleton (const singleton<T>&) = delete ;
21
+ singleton (const singleton<T>&) = default ;
22
22
singleton& operator =(const singleton<T>&) = delete ;
23
23
24
+ template <typename U>
25
+ inline bool operator ==(const U& rhs) const {
26
+ return std::is_same<T,U>::value;
27
+ }
28
+ template <typename U>
29
+ inline bool operator !=(const U& rhs) const {
30
+ return !(*this == rhs);
31
+ }
32
+
24
33
protected:
25
34
singleton ()
26
35
{
Original file line number Diff line number Diff line change @@ -17,12 +17,33 @@ class my_singleton : public dpc::singleton<my_singleton> {
17
17
18
18
TEST (DessignPatternSingletonTest, SingletonInstantiation)
19
19
{
20
- my_singleton a ;
20
+ auto a = my_singleton::get () ;
21
21
my_singleton b;
22
22
23
+ ASSERT_FALSE (std::addressof (a) == std::addressof (b));
24
+ ASSERT_TRUE (std::addressof (*a) == std::addressof (*b));
25
+ ASSERT_TRUE (std::addressof (a.get ()) == std::addressof (b.get ()));
23
26
ASSERT_STREQ (a->instance_addr ().c_str (), b->instance_addr ().c_str ());
24
- ASSERT_STREQ (my_singleton::get ().instance_addr ().c_str (),
25
- a->instance_addr ().c_str ());
27
+ }
28
+
29
+ TEST (DessignPatternSingletonTest, SingletonEquality)
30
+ {
31
+ my_singleton a;
32
+ my_singleton b;
33
+
34
+ ASSERT_EQ (a, b);
35
+ }
36
+
37
+ TEST (DessignPatternSingletonTest, SingletonNotEquality)
38
+ {
39
+ my_singleton a;
40
+
41
+ class my_class {};
42
+ my_class b;
43
+ int c = 0 ;
44
+
45
+ ASSERT_TRUE (a != b);
46
+ ASSERT_TRUE (a != c);
26
47
}
27
48
28
49
int main (int argc, char **argv) {
You can’t perform that action at this time.
0 commit comments