PrevUpHomeNext

esv::diff_size_cast


Do not compare your life with others'.

esv::diff_size_cast

esv::diff_size_cast is used to cast from one integral value to another integral value. If the value is greater than the max value of target type, or the value is less than the min value of target type, the compilation will fail.

template <esv::integral_meric target_type, esv::integral_meric auto source_value>
	requires (esv::in_scope(source_value, esv::min_v<target_type>, esv::max_v<target_type>))
constexpr inline target_type diff_size_cast = esv::meric_static_cast<target_type>(source_value);

c++ example

#include <esvcpp/core.hpp>

int main()
{
	constexpr esv::i32 x = 123;
	constexpr auto x1 = esv::diff_size_cast<esv::i16, x>;

	constexpr esv::i32 x2 = 128;

	// Error: Constraint not satisfied.
	// (Because esv::i8_max is 127, x2 is greater than esv::i8_max)
	auto x3 = esv::diff_size_cast<esv::i8, x2>;
}

See Also

esv::gnrk_static_cast

esv::meric_static_cast

esv::mean_t


PrevUpHomeNext

esv::print