PrevUpHomeNext

esv::gnrk_static_cast


Be not afraid of tomorrow.

esv::gnrk_static_cast

esv::gnrk_static_cast - Esvcpp Generic Static Cast.

esv::gnrk_static_cast tries to static_cast types as more as possible: esv::meric_static_cast, simple-constructible-with cast, and static_cast .

esv::gnrk_static_cast rules over three casts:

esv::gnrk_static_cast c++ example

#include <esvcpp/core.hpp>

int main()
{
	constexpr esv::ix32 a = 123;
	constexpr auto b = esv::gnrk_static_cast<esv::fx64>(a);	// It calls esv::meric_static_cast internally
	esv::print(a, b);	// 123 123.0

	constexpr float c = 3.4;
	constexpr auto d = esv::gnrk_static_cast<int>(c);	// It calls static_cast internally
	esv::print(c, d);	// 3.4 3

	class cat_box
	{
	private:
		esv::ix32 value;
	public:
		constexpr cat_box(const esv::ix32 & value): value{value}
		{
		}
		constexpr auto operator()() const
		{
			return value;
		}
	};
	constexpr esv::ix32 e = 234;
	constexpr auto f = esv::gnrk_static_cast<cat_box>(e);	// It calls target_type{value__} internally
	esv::print(e, f());	// 234 234

	esv::ix32 g = 345;
	decltype(auto) h = esv::gnrk_static_cast<esv::ix32 &>(g);
	++h;
	esv::print(g, h);	// 346 346
}

See Also

esv::meric_static_cast

esv::gnrk_static_convertible


PrevUpHomeNext

E