Details
-
Improvement
-
Resolution: Fixed
-
Major - P3
-
None
-
None
-
Fully Compatible
-
Service arch 2020-12-14
Description
Only needs invariant.h, should not include assert_util.h.
base/checked_cast.h relies on invariant() to perform its checks and needs no other assert_util.h declarations. The errant assert_util.h dependency makes checked_cast.h inaccessible to any header that assert_util.h depends on (we need it for status.h and can't currently have it). This is an unnecessary restriction. It can be whitelisted to use the invariant.h header just like string_data.h and the small set of other assert_util.h dependencies.
As for the content of checked_cast.h:
|
|
template <typename T, typename U>
|
T checked_cast(const U& u);
|
template <typename T, typename U>
|
T checked_cast(U& u);
|
|
|
template <typename T, typename U>
|
std::shared_ptr<T> checked_pointer_cast(const std::shared_ptr<U>& u);
|
|
We should provide && overloads for these. A checked_cast of an rvalue should be a move, not a copy. Casting a shared_ptr&& should not increment its refcount!
In C++20 the underlying std::static_pointer_cast and std::dynamic_pointer_cast are getting && argument overloads to avoid this cost. There's no reason we shouldn't be ready for that.
The implementation of these functions is a very C++98 dispatch to a static member function of a struct template specialization, keyed off of bool kDebugBuild. Super old school. This is silly in C++17 where we have if constexpr and can write that kind of dispatching very naturally in a single function body.
There's some urgency to this as it blocks an improvement to status.h.
Attachments
Issue Links
- is depended on by
-
SERVER-52904 Improve implementation of mongo::Status
-
- Closed
-