PrevUpHomeNext

Class Types


Table of Contents

utx::ix8
utx::ix16
utx::ix32
utx::ix64
utx::ixlast
utx::ixmax
utx::ixlost
utx::ux8
utx::ux16
utx::ux32
utx::ux64
utx::uxlast
utx::uxmax
utx::uxlost
utx::fx32
utx::fx64
utx::fx128
utx::fxmax
utx::fxlast
utx::mbx
utx::mtx
utx::mtx8
utx::mtx16
utx::mtx32
utx::wmtx
.is_nan method
.is_inf method
.abs method
.floor_fpp method
.floor method
.fpp method
.ceil method
.quo_mod method
.quo method
.mod method
.cast method

utxcpp class types

utx::class_type

utx::class_type is used to define basic integral and floating point types, but it is class. So the data types defined by utx::class_type have both the basic data type features and object-oriented features.

operators defined in utx::class_type :

utx::mbx

bool class

using mbx = utx::class_type<utx::mb>;

utx::ux8 utx::ux16 utx::ux32 utx::ux64 utx::uxmax

unsigned integral class

using ux8 = utx::class_type<utx::u8>;
using ux16 = utx::class_type<utx::u16>;
using ux32 = utx::class_type<utx::u32>;
using ux64 = utx::class_type<utx::u64>;
using uxmax = utx::class_type<utx::umax>;

utx::ix8 utx::ix16 utx::ix32 utx::ix64 utx::ixmax

signed integral class

using ix8 = utx::class_type<utx::i8>;
using ix16 = utx::class_type<utx::i16>;
using ix32 = utx::class_type<utx::i32>;
using ix64 = utx::class_type<utx::i64>;
using ixmax = utx::class_type<utx::imax>;

utx::fx32 utx::fx64 utx::fx128 utx::fxmax

floating point class

using fx32 = utx::class_type<utx::f32>;
using fx64 = utx::class_type<utx::f64>;
using fx128 = utx::class_type<utx::f128>;
using fxmax = utx::class_type<utx::fmax>;

.value(), operator(), operator basic_type

These three member functions return __value by value.

.value_ref()

Member function .value_ref() returns __value by ref.

utx::class_type does not overload .value() to support both by-value and by-ref, but uses .value_ref() to get by ref.

include

utxcpp/types.hpp :

#include <utxcpp/types.hpp>

utxcpp/types.hpp is included by the whole system, so using utxcpp/core.hpp works too:

#include <utxcpp/core.hpp>

examples

example: Using utx::class_type, and constexpr support

#include <utxcpp/core.hpp>

int main()
{
	constexpr utx::ux64 a = 123;
	constexpr utx::ix64 b = 321;
	constexpr utx::fx64 c = 321.123;
	utx::print(a, b, c);
}

output:

123 321 321.123000

example: utx::class_type value as template parameter

#include <utxcpp/core.hpp>

template <auto __value>
class power
{
public:
	constexpr auto operator()() const
	{
		return __value*__value;
	}
};

int main()
{
	constexpr utx::fx32 value = 123.456f;
	constexpr auto p2 = power<value>{}();
	utx::print(p2);
}

output:

15241.383789

example: utx::class_type inheritence, polymorphism, pointer

utx::class_type does not support polymorphism itself, but it can be used as the base class of another polymorphism base class.

#include <utxcpp/core.hpp>
#include <memory>

class base: public utx::ix64
{
public:
	base(const auto & value): utx::ix64{value}
	{
	}
	virtual ~base()
	{
		utx::print("~base");
	}
};

class derived: virtual public base
{
public:
	derived(const auto & value): base{value}
	{
	}
	~derived()
	{
		utx::print("~derived");
	}
};

int main()
{
	base * ptr = new derived{123};
	utx::print(*ptr);
	delete ptr;

	{
		std::unique_ptr<base> ptr = std::make_unique<derived>(32);
		utx::print(*ptr);
	}
}

output:

123
~derived
~base
32
~derived
~base

PrevUpHomeNext

E

U