| 1112 | } |
| 1113 | |
| 1114 | void test_macros_and_serializers() |
| 1115 | { |
| 1116 | std::unique_ptr<string> uptr1, uptr2, uptr3, uptr4; |
| 1117 | uptr1.reset(new string("hello from uptr1")); |
| 1118 | |
| 1119 | my_custom_type t1, t2, t3, t4; |
| 1120 | t1.a = 1; |
| 1121 | t1.b = 2.5; |
| 1122 | t1.c = {1.f, 2.f, 3.f, 4.f, 5.f}; |
| 1123 | t1.d.push_back("hello from back of list"); |
| 1124 | t1.d.push_back("world from back of list"); |
| 1125 | t1.d.push_front("world from front of list"); |
| 1126 | t1.d.push_front("hello from front of list"); |
| 1127 | t1.e.push_front("world from forward_list"); |
| 1128 | t1.e.push_front("hello from forward_list"); |
| 1129 | t1.f = make_pair(2, "hello from pair"); |
| 1130 | std::get<0>(t1.g) = 2; |
| 1131 | std::get<1>(t1.g) = "hello from tuple"; |
| 1132 | std::get<2>(t1.g) = 1.4142; |
| 1133 | t1.h["key"] = 15; |
| 1134 | t1.i["key"] = 16; |
| 1135 | t1.i.insert({"inserted key", 17}); |
| 1136 | t1.j.insert({"key", 21}); |
| 1137 | t1.j.insert({"key", 22}); |
| 1138 | t1.j.insert({"inserted key", 23}); |
| 1139 | t1.j.insert({"inserted key", 24}); |
| 1140 | t1.j.insert({"key", 25}); |
| 1141 | t1.j.insert({"key", 26}); |
| 1142 | t1.k.insert({"inserted key", 27}); |
| 1143 | t1.k.insert({"inserted key", 28}); |
| 1144 | t1.l.insert("hello from set"); |
| 1145 | t1.m.insert("hello from unordered_set"); |
| 1146 | t1.n.insert("hello from multiset"); |
| 1147 | t1.n.insert("hello from multiset"); |
| 1148 | t1.o.insert("hello from unordered_multiset"); |
| 1149 | t1.o.insert("hello from unordered_multiset"); |
| 1150 | t1.ptr_shared1 = make_shared<string>("hello from shared_ptr"); |
| 1151 | dlib::rand rng(std::time(NULL)); |
| 1152 | for (int i = 0 ; i < 1024 ; i++) |
| 1153 | t1.p.push_back(rng.get_random_gaussian()); |
| 1154 | #if __cplusplus >= 201703L |
| 1155 | t1.q = "hello there from std::variant, welcome!"; |
| 1156 | t1.r = {"hello from optional vector of string"}; |
| 1157 | #endif |
| 1158 | t2.a = 2; |
| 1159 | t2.b = 4.0; |
| 1160 | t2.c.resize(10); |
| 1161 | |
| 1162 | my_custom_type_array v1, v2; |
| 1163 | v1.v.push_back(t1); |
| 1164 | v1.v.push_back(t2); |
| 1165 | |
| 1166 | #if __cplusplus >= 201703L |
| 1167 | std::variant<int,float,std::string,immutable_type> i1, i2; |
| 1168 | i1 = std::string("hello from variant that can hold an immutable type"); |
| 1169 | #else |
| 1170 | // make it so that we don't need to add #if guards in every block below |
| 1171 | std::string i1, i2; |
no test coverage detected