1#ifndef LIPH_LANG_CASTS_H_
2#define LIPH_LANG_CASTS_H_
10template <
typename To,
typename From>
15template <
typename To,
typename From>
18 implicit_cast<From *, To>(0);
21 assert(f ==
nullptr ||
dynamic_cast<To
>(f) !=
nullptr);
23 return static_cast<To
>(f);
26template <
typename To,
typename From>
28 using Pointer =
typename std::remove_reference<To>::type *;
30 implicit_cast<From *, Pointer>(0);
33 assert(
dynamic_cast<Pointer
>(&f) !=
nullptr);
35 return *
static_cast<Pointer
>(&f);
38template <
typename To,
typename From>
40 static_assert(
sizeof(From) ==
sizeof(To),
"bit_cast_with_different_sizes");
42 memcpy(&dest, &from,
sizeof(dest));
Definition: algorithm.h:10
To bit_cast(const From &from)
Definition: casts.h:39
To down_cast(From *f)
Definition: casts.h:16
To implicit_cast(const From &f)
Definition: casts.h:11