| 131 | } |
| 132 | |
| 133 | void test_try_invoke() |
| 134 | { |
| 135 | int value = 0; |
| 136 | |
| 137 | auto foo = [&]{ value++; }; |
| 138 | auto bar = [&](int i) { value += i; }; |
| 139 | auto baz = [&](int i, int j) { value += (i+j); }; |
| 140 | |
| 141 | DLIB_TEST(try_invoke(foo)); |
| 142 | DLIB_TEST(value == 1); |
| 143 | DLIB_TEST(!try_invoke(foo, 1)); |
| 144 | DLIB_TEST(value == 1); |
| 145 | DLIB_TEST(!try_invoke(foo, 1, 2)); |
| 146 | DLIB_TEST(value == 1); |
| 147 | |
| 148 | DLIB_TEST(!try_invoke(bar)); |
| 149 | DLIB_TEST(value == 1); |
| 150 | DLIB_TEST(try_invoke(bar, 1)); |
| 151 | DLIB_TEST(value == 2); |
| 152 | DLIB_TEST(!try_invoke(bar, 1, 2)); |
| 153 | DLIB_TEST(value == 2); |
| 154 | |
| 155 | DLIB_TEST(!try_invoke(baz)); |
| 156 | DLIB_TEST(value == 2); |
| 157 | DLIB_TEST(!try_invoke(baz, 1)); |
| 158 | DLIB_TEST(value == 2); |
| 159 | DLIB_TEST(try_invoke(baz, 1, 2)); |
| 160 | DLIB_TEST(value == 5); |
| 161 | } |
| 162 | |
| 163 | template<typename T> |
| 164 | using set_i_pred = decltype(std::declval<T>().set_i(int{})); |
no test coverage detected