| 53 | |
| 54 | template <typename Storage> |
| 55 | void test_storage_basic() |
| 56 | { |
| 57 | Storage a; |
| 58 | DLIB_TEST(a.get_ptr() == nullptr); |
| 59 | DLIB_TEST(a.is_empty()); |
| 60 | DLIB_TEST(a.template contains<int>() == false); |
| 61 | int value = 5; |
| 62 | a = value; |
| 63 | DLIB_TEST(a.get_ptr() != nullptr); |
| 64 | DLIB_TEST(!a.is_empty()); |
| 65 | DLIB_TEST(a.template contains<int>()); |
| 66 | DLIB_TEST(!a.template contains<std::string>()); |
| 67 | DLIB_TEST(a.template cast_to<int>() == 5); |
| 68 | DLIB_TEST(a.template get<int>() == 5); |
| 69 | |
| 70 | Storage b = a; |
| 71 | DLIB_TEST(b.get_ptr() != nullptr); |
| 72 | DLIB_TEST(!b.is_empty()); |
| 73 | DLIB_TEST(b.template contains<int>()); |
| 74 | DLIB_TEST(b.template cast_to<int>() == 5); |
| 75 | DLIB_TEST(b.template get<int>() == 5); |
| 76 | DLIB_TEST(a.get_ptr() != nullptr); |
| 77 | DLIB_TEST(!a.is_empty()); |
| 78 | DLIB_TEST(a.template contains<int>()); |
| 79 | DLIB_TEST(a.template cast_to<int>() == 5); |
| 80 | DLIB_TEST(a.template get<int>() == 5); |
| 81 | |
| 82 | DLIB_TEST(*static_cast<int*>(a.get_ptr()) == 5); |
| 83 | DLIB_TEST(*static_cast<int*>(b.get_ptr()) == 5); |
| 84 | |
| 85 | |
| 86 | a.clear(); |
| 87 | DLIB_TEST(a.get_ptr() == nullptr); |
| 88 | DLIB_TEST(a.is_empty()); |
| 89 | DLIB_TEST(!a.template contains<int>()); |
| 90 | |
| 91 | } |
| 92 | |
| 93 | void test_type_erasure() |
| 94 | { |