GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
utility.hpp
Go to the documentation of this file.
1// ___ __ __ ___
2// / __| \/ | _ \ GMP(Generative Metaprogramming)
3// | (_ | |\/| | _/ version 0.2.0
4// \___|_| |_|_| https://github.com/lkimuk/gmp
5//
6// SPDX-FileCopyrightText: 2023-2026 Miles Li <https://www.cppmore.com/>
7// SPDX-License-Identifier: MIT
8//
9// This file is part of the GMP (Generative Metaprogramming) library.
10// Full project source: https://github.com/lkimuk/gmp
11
12#ifndef GMP_META_UTILITY_HPP_
13#define GMP_META_UTILITY_HPP_
14
15namespace gmp {
16
29template<auto>
31 explicit constant_arg_t() = default;
32};
33
39template<auto V>
41
48struct any { template<typename T> operator T() const; };
49
52namespace detail {
53
54template<typename T>
55struct wrapper {
56 const T value{};
57 static const wrapper<T> long_lifetime_obj;
58
59 wrapper() = default;
60 wrapper(const wrapper&) = delete;
61 wrapper& operator=(const wrapper&) = delete;
62 wrapper& operator=(wrapper&&) = delete;
63};
64
65template<typename T>
66const wrapper<T> wrapper<T>::long_lifetime_obj{};
67
68} // namespace detail
69
80template<typename T>
81consteval const T& as_value() noexcept {
82 return detail::wrapper<T>::long_lifetime_obj.value;
83}
84
87} // namespace gmp
88
89#endif // GMP_META_UTILITY_HPP_
consteval auto enum_values()
Get all enumerator values of an enumeration type at compile-time.
Definition meta.hpp:155
constexpr constant_arg_t< V > constant_arg
A ready-to-use constant_arg_t<V> object for a compile-time value.
Definition utility.hpp:40
consteval const T & as_value() noexcept
Expose a default-constructed value of type T as a compile-time reference.
Definition utility.hpp:81
Definition lock.hpp:21
A placeholder type implicitly convertible to any type.
Definition utility.hpp:48
Wrap a compile-time value as a distinct function argument type.
Definition utility.hpp:30
constant_arg_t()=default