xieite::wrap_value<>

Defined in header <xieite/meta/wrap_value.hpp>

A NTTP wrapper.


Definition

template<decltype(auto) x>
struct wrap_value {
	static constexpr decltype(auto) value = x;

	[[nodiscard]] explicit(false) constexpr operator decltype(auto)() const noexcept;

	[[nodiscard]] static constexpr decltype(auto) operator()() noexcept;

	[[nodiscard]] friend constexpr auto operator<=>(xieite::wrap_value<x>, auto&& rhs) XIEITE_ARROW(
		x <=> XIEITE_FWD(rhs)
	)

	[[nodiscard]] friend constexpr auto operator==(xieite::wrap_value<x>, auto&& rhs) XIEITE_ARROW(
		x == XIEITE_FWD(rhs)
	)
};


Example

template<typename T, std::size_t length>
struct fixed_array {
	static constexpr auto size = xieite::wrap_value<length>();

	xieite::type<T[length]> data;
};

static_assert(fixed_array<int, 5>::size == 5);

static_assert(fixed_array<int, 5>().size() == 5);
[View in Compiler Explorer]