| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | /* | ||
| 3 | KUMI - Compact Tuple Tools | ||
| 4 | Copyright : KUMI Project Contributors | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //====================================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | namespace kumi | ||
| 11 | { | ||
| 12 | //==================================================================================================================== | ||
| 13 | /** | ||
| 14 | @ingroup kumi_types | ||
| 15 | |||
| 16 | @class as | ||
| 17 | @brief Lightweight type-wrapper | ||
| 18 | |||
| 19 | kumi::as Wraps type into a constexpr, trivially constructible empty class to optimize passing type parameters | ||
| 20 | via object instead of via template parameters. A specialisation is provided if T is void. | ||
| 21 | |||
| 22 | @tparam T Type to wrap | ||
| 23 | |||
| 24 | ## Example: | ||
| 25 | @include doc/infra/as.cpp | ||
| 26 | **/ | ||
| 27 | //==================================================================================================================== | ||
| 28 | template<typename T> struct as | ||
| 29 | { | ||
| 30 | //! @brief Wrapped type | ||
| 31 | using type = T; | ||
| 32 | |||
| 33 | 92 | constexpr as() noexcept {} | |
| 34 | |||
| 35 | 5 | explicit constexpr as(T const&) noexcept {} | |
| 36 | |||
| 37 | constexpr inline operator std::type_identity<T>() const noexcept { return {}; } | ||
| 38 | }; | ||
| 39 | |||
| 40 | template<> struct as<void> | ||
| 41 | { | ||
| 42 | using type = void; | ||
| 43 | |||
| 44 | 1 | constexpr as() noexcept {} | |
| 45 | }; | ||
| 46 | } | ||
| 47 |