Basic types¶
any¶
xnetwork::any is a backport of the C++17 class std::any. The class describes a type-safe container for single values of any type:
#include <iostream>
#include "xnetwork/xany.hpp"
xnetwork::any a = 1;
std::cout << a.type().name() << ": " << xnetwork::any_cast<int>(a) << std::endl;
// => i: 1
try
{
std::cout << xnetwork::any_cast<float>(a) << std::endl;
}
catch(const xnetwork::bad_any_cast& e)
{
std::cout << e.what() << std::endl;
}
// => bad any_cast
a.reset();
std::cout << std::boolalpha << a.empty() << std::endl;
// => true
The API of xnetwork::any is the same as that of std::any. Full documentation can be found on cppreference.
xbasic_fixed_string¶
TODO
xcomplex¶
xcomplex is the equivalent to std::complex, where the real ang imaginary part can be stored either as values, or as references. Therefore, it can be used as a proxy on real values already initialized. This is particularly interesting for storing real and imaginary parts in different containers, and gather them as complex values for computation. This allows optimzations (such as vectorization) on the real and imgaginary values.
#include <iostream>
#include <vector>
#include "xnetwork/xcomplex.hpp"
std::vector<double> arg1_real = { 1., 2.};
std::vector<double> arg1_imag = { 3., 4.};
std::vector<double> arg2_real = { 2., 4.};
std::vector<double> arg2_real = { 1., 3.};
std::vector<double> res_real(2);
std::vector<double> res_imag(2);
using complex = xnetwork::xcomplex<double&, double&>;
using const_complex = xnetwork::xcomplex<const double&, const double&>;
for (size_t i = 0; i < 2; ++i)
{
complex res(res_real[i], res_img[i]);
res = const_complex(arg1_real, arg1_imag) * const_complex(arg2_real, arg2_imag);
std::cout << "res = (" << res.real(), << ", " << res.imag() << std::endl;
}
The API of xnetwork::xcomplex is the same as that of std::complex, with the ability to store values as references. Full documentation can be found on cppreference.
half_float¶
The half_float class implements an IEEE-conformant half-precision floating-point type with the usual arithmetic operators and conversions. It is implicitly convertible from single-precision floating-point, which makes expressions and functions with mixed-type operands to be of the most precise operand type.
#include <iostream<
#include "xnetwork/xhalf.hpp"
xnetwork::half_float f0 = 1.0f;
xnetwork::half_float f1 = 2.0f;
auto res = f0 + f1;
std::cout << res << std::endl;
xmasked_value¶
TODO
xoptional¶
TODO
xvariant¶
TODO