|
| 1 | +// Copryright (C) 2022 Arthur LAURENT <arthur.laurent4@gmail.com> |
| 2 | +// This file is subject to the license terms in the LICENSE file |
| 3 | +// found in the top-level of this distribution |
| 4 | + |
| 5 | +#ifndef STORMKIT_ASCASTS_MACRO_HPP |
| 6 | +#define STORMKIT_ASCASTS_MACRO_HPP |
| 7 | + |
| 8 | +#include <stormkit/Core/PlatformMacro.hpp> |
| 9 | + |
| 10 | +#define ASCASTER_STRICT_DECLARE(_To, _From) \ |
| 11 | + template<stormkit::core::meta::IsStrict<_To> To, stormkit::core::meta::IsStrict<_From> From> \ |
| 12 | + struct stormkit::casts::AsCaster<To, From> { \ |
| 13 | + static constexpr auto operator()(const From& from, \ |
| 14 | + const std::source_location& location) noexcept -> To; \ |
| 15 | + }; |
| 16 | + |
| 17 | +#define ASCASTER_STRICT_DEFINE(_To, _From) \ |
| 18 | + template<stormkit::core::meta::IsStrict<_To> To, stormkit::core::meta::IsStrict<_From> From> \ |
| 19 | + STORMKIT_FORCE_INLINE constexpr auto stormkit::casts::AsCaster<To, From>::operator()( \ |
| 20 | + const From& from, \ |
| 21 | + [[maybe_unused]] const std::source_location& location) noexcept -> To |
| 22 | + |
| 23 | +#define ASCASTER_STRICT(_To, _From) \ |
| 24 | + ASCASTER_STRICT_DECLARE(_To, _From) \ |
| 25 | + ASCASTER_STRICT_DEFINE(_To, _From) |
| 26 | + |
| 27 | +#define ASCASTER_DECLARE(_To, _From) \ |
| 28 | + template<_To To, _From From> \ |
| 29 | + struct stormkit::casts::AsCaster<To, From> { \ |
| 30 | + static constexpr auto operator()(const From& from, \ |
| 31 | + const std::source_location& location) noexcept -> To; \ |
| 32 | + }; |
| 33 | + |
| 34 | +#define ASCASTER_DEFINE(_To, _From) \ |
| 35 | + template<_To To, _From From> \ |
| 36 | + STORMKIT_FORCE_INLINE constexpr auto stormkit::casts::AsCaster<To, From>::operator()( \ |
| 37 | + const From& from, \ |
| 38 | + [[maybe_unused]] const std::source_location& location) noexcept -> To |
| 39 | + |
| 40 | +#define ASCASTER(_To, _From) \ |
| 41 | + ASCASTER_DECLARE(_To, _From) \ |
| 42 | + ASCASTER_DEFINE(_To, _From) |
| 43 | + |
| 44 | +#define NARROWCASTER_STRICT_DECLARE(_To, _From) \ |
| 45 | + template<stormkit::core::meta::IsStrict<_To> To, stormkit::core::meta::IsStrict<_From> From> \ |
| 46 | + struct stormkit::casts::NarrowCaster<To, From> { \ |
| 47 | + static constexpr auto operator()(const From& from, \ |
| 48 | + const std::source_location& location) noexcept -> To; \ |
| 49 | + }; |
| 50 | + |
| 51 | +#define NARROWCASTER_STRICT_DEFINE(_To, _From) \ |
| 52 | + template<stormkit::core::meta::IsStrict<_To> To, stormkit::core::meta::IsStrict<_From> From> \ |
| 53 | + STORMKIT_FORCE_INLINE constexpr auto stormkit::casts::NarrowCaster<To, From>::operator()( \ |
| 54 | + const From& from, \ |
| 55 | + [[maybe_unused]] const std::source_location& location) noexcept -> To |
| 56 | + |
| 57 | +#define NARROWCASTER_STRICT(_To, _From) \ |
| 58 | + NARROWCASTER_STRICT_DECLARE(_To, _From) \ |
| 59 | + NARROWCASTER_STRICT_DEFINE(_To, _From) |
| 60 | + |
| 61 | +#define NARROWCASTER_DECLARE(_To, _From) \ |
| 62 | + template<_To To, _From From> \ |
| 63 | + struct stormkit::casts::NarrowCaster<To, From> { \ |
| 64 | + static constexpr auto operator()(const From& from, \ |
| 65 | + const std::source_location& location) noexcept -> To; \ |
| 66 | + }; |
| 67 | + |
| 68 | +#define NARROWCASTER_DEFINE(_To, _From) \ |
| 69 | + template<_To To, _From From> \ |
| 70 | + STORMKIT_FORCE_INLINE constexpr auto stormkit::casts::NarrowCaster<To, From>::operator()( \ |
| 71 | + const From& from, \ |
| 72 | + [[maybe_unused]] const std::source_location& location) noexcept -> To |
| 73 | + |
| 74 | +#define NARROWCASTER(_To, _From) \ |
| 75 | + NARROWCASTER_DECLARE(_To, _From) \ |
| 76 | + NARROWCASTER_DEFINE(_To, _From) |
| 77 | + |
| 78 | +#endif |
0 commit comments