Table of Contents
esvcpp class types
esv::class_type is used to define basic integral and floating point types, but it is class. So the data types defined by esv::class_type have both the basic data type features and object-oriented features.
operators defined in esv::class_type :
bool class
using mbx = esv::class_type<esv::mb>;
unsigned integral class
using ux8 = esv::class_type<esv::u8>; using ux16 = esv::class_type<esv::u16>; using ux32 = esv::class_type<esv::u32>; using ux64 = esv::class_type<esv::u64>; using uxmax = esv::class_type<esv::umax>;
signed integral class
using ix8 = esv::class_type<esv::i8>; using ix16 = esv::class_type<esv::i16>; using ix32 = esv::class_type<esv::i32>; using ix64 = esv::class_type<esv::i64>; using ixmax = esv::class_type<esv::imax>;
floating point class
using fx32 = esv::class_type<esv::f32>; using fx64 = esv::class_type<esv::f64>; using fx128 = esv::class_type<esv::f128>; using fxmax = esv::class_type<esv::fmax>;
These three member functions return __value by value.
Member function .value_ref() returns __value by ref.
esv::class_type does not overload .value() to support both by-value and by-ref, but uses .value_ref() to get by ref.
esvcpp/types.hpp :
#include <esvcpp/types.hpp>
esvcpp/types.hpp is included by the whole system, so using esvcpp/core.hpp works too:
#include <esvcpp/core.hpp>
#include <esvcpp/core.hpp> int main() { constexpr esv::ux64 a = 123; constexpr esv::ix64 b = 321; constexpr esv::fx64 c = 321.123; esv::print(a, b, c); }
output:
123 321 321.123000
#include <esvcpp/core.hpp> template <auto __value> class power { public: constexpr auto operator()() const { return __value*__value; } }; int main() { constexpr esv::fx32 value = 123.456f; constexpr auto p2 = power<value>{}(); esv::print(p2); }
output:
15241.383789
esv::class_type does not support polymorphism itself, but it can be used as the base class of another polymorphism base class.
#include <esvcpp/core.hpp> #include <memory> class base: public esv::ix64 { public: base(const auto & value): esv::ix64{value} { } virtual ~base() { esv::print("~base"); } }; class derived: virtual public base { public: derived(const auto & value): base{value} { } ~derived() { esv::print("~derived"); } }; int main() { base * ptr = new derived{123}; esv::print(*ptr); delete ptr; { std::unique_ptr<base> ptr = std::make_unique<derived>(32); esv::print(*ptr); } }
output:
123 ~derived ~base 32 ~derived ~base