36 template<
typename Target,
typename Source>
37 struct NarrowCast_Imp {
39 const Target r =
static_cast<Target
>(v);
40 if(
static_cast<Source
>(r) != v )
41 throw std::runtime_error(
"narrow_cast<>() failed");
47 template<
typename SameType>
48 struct NarrowCast_Imp<SameType, SameType> {
49 static inline SameType
narrow_cast( SameType v )
noexcept {
59 template<
typename Target,
typename Source>
61 return NarrowCast_Imp<Target, Source>::narrow_cast(v);
65 template <
typename Target,
typename Source>
66 std::unique_ptr<Target> dynamic_unique_cast(std::unique_ptr<Source>&& source) {
67 if(
auto* casted =
dynamic_cast<Target*
>(source.get()) ) {
69 return std::unique_ptr<Target>( casted );
Namespace of common utility classes and methods.
Definition Helpers.h:43
Target narrow_cast(Source v)
Safe cast for casting numeric values.
Definition NarrowCast.h:60