| 1352 | |
| 1353 | template <typename T> |
| 1354 | inline static std::shared_ptr<T> |
| 1355 | try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) { |
| 1356 | // Pre C++17, this code path exploits undefined behavior, but is known to work on many platforms. |
| 1357 | // Use at your own risk! |
| 1358 | // See also https://en.cppreference.com/w/cpp/memory/enable_shared_from_this, and in particular |
| 1359 | // the `std::shared_ptr<Good> gp1 = not_so_good.getptr();` and `try`-`catch` parts of the example. |
| 1360 | #if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912) |
| 1361 | return holder_value_ptr->weak_from_this().lock(); |
| 1362 | #else |
| 1363 | try { |
| 1364 | return holder_value_ptr->shared_from_this(); |
| 1365 | } catch (const std::bad_weak_ptr &) { |
| 1366 | return nullptr; |
| 1367 | } |
| 1368 | #endif |
| 1369 | } |
| 1370 | |
| 1371 | // For silencing "unused" compiler warnings in special situations. |
| 1372 | template <typename... Args> |
no test coverage detected