Table of Contents
utxcpp class types
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 :
bool class
using mbx = utx::class_type<utx::mb>;
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>;
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>;
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>;
These three member functions return __value by value.
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.
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>
#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
#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
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