#include "Stroika/Foundation/StroikaPreComp.h"
#include <memory>
#include "Stroika/Foundation/Debug/Assertions.h"
#include "Cast.inl"
Go to the source code of this file.
|
template<typename T , typename T1 > |
T | Stroika::Foundation::Debug::UncheckedDynamicCast (T1 &&arg) noexcept |
| return the same value as dynamic_cast<T> would have, except instead of checking nullptr, only check in DEBUG builds, and there ASSERT != null (if original pointer not null)
|
|
template<typename T , typename T1 > |
std::shared_ptr< T > | Stroika::Foundation::Debug::UncheckedDynamicPointerCast (const std::shared_ptr< T1 > &arg) noexcept |
| Produce the same result as dynamic_pointer_cast if the successful case (non-null) - with better performance.
|
|
◆ UncheckedDynamicCast()
template<typename T , typename T1 >
T Stroika::Foundation::Debug::UncheckedDynamicCast |
( |
T1 && |
arg | ) |
|
|
noexcept |
return the same value as dynamic_cast<T> would have, except instead of checking nullptr, only check in DEBUG builds, and there ASSERT != null (if original pointer not null)
- Precondition
- arg != nullptr
Use where you would want to check Assert (dynamic_cast<const T*> (&ir) != nullptr) and then do static_cast<> instead;)
AssertMember (&ir, IteratorRep_);
auto& mir = static_cast<const IteratorRep_&> (ir);
The purpose of this function is to gain the performance of static_cast<> but the safety / checking of dynamic_cast (in debug builds).
- Example Usage
auto& mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
- Example Usage
virtual bool Equals (const IRep* rhs) const override
{
const MyIterRep_* rrhs = Debug::UncheckedDynamicCast<const MyIterRep_*> (rhs);
return fData_.data () == rrhs->fData_.data () and fIdx_ == rrhs->fIdx_;
}
#define RequireMember(p, c)
#define RequireNotNull(p)
- See also
- https://stackoverflow.com/questions/28002/regular-cast-vs-static-cast-vs-dynamic-cast
- Note
- this does NOT work (should be checked somehow/assert/type info
Definition at line 13 of file Cast.inl.
◆ UncheckedDynamicPointerCast()
template<typename T , typename T1 >
std::shared_ptr< T > Stroika::Foundation::Debug::UncheckedDynamicPointerCast |
( |
const std::shared_ptr< T1 > & |
arg | ) |
|
|
noexcept |
Produce the same result as dynamic_pointer_cast if the successful case (non-null) - with better performance.
- Precondition
- arg != nullptr
-
dynamic_pointer_cast<T> (arg) != nullptr
- See also
- UncheckedDynamicCast and dynamic_pointer_cast
Definition at line 42 of file Cast.inl.