/** * @file src/utility.h * @brief todo */ #pragma once #include #include #include #include #include #include #include #include #include #include #define KITTY_WHILE_LOOP(x, y, z) \ { \ x; \ while (y) z \ } template struct argument_type; template struct argument_type { typedef U type; }; #define KITTY_USING_MOVE_T(move_t, t, init_val, z) \ class move_t { \ public: \ using element_type = typename argument_type::type; \ \ move_t(): el { init_val } {} \ template \ move_t(Args &&...args): el { std::forward(args)... } {} \ move_t(const move_t &) = delete; \ \ move_t(move_t &&other) noexcept: el { std::move(other.el) } { \ other.el = element_type { init_val }; \ } \ \ move_t & \ operator=(const move_t &) = delete; \ \ move_t & \ operator=(move_t &&other) { \ std::swap(el, other.el); \ return *this; \ } \ element_type * \ operator->() { return ⪙ } \ const element_type * \ operator->() const { return ⪙ } \ \ inline element_type \ release() { \ element_type val = std::move(el); \ el = element_type { init_val }; \ return val; \ } \ \ ~move_t() z \ \ element_type el; \ } #define KITTY_DECL_CONSTR(x) \ x(x &&) noexcept = default; \ x &operator=(x &&) noexcept = default; \ x(); #define KITTY_DEFAULT_CONSTR_MOVE(x) \ x(x &&) noexcept = default; \ x &operator=(x &&) noexcept = default; #define KITTY_DEFAULT_CONSTR_MOVE_THROW(x) \ x(x &&) = default; \ x &operator=(x &&) = default; \ x() = default; #define KITTY_DEFAULT_CONSTR(x) \ KITTY_DEFAULT_CONSTR_MOVE(x) \ x(const x &) noexcept = default; \ x &operator=(const x &) = default; #define TUPLE_2D(a, b, expr) \ decltype(expr) a##_##b = expr; \ auto &a = std::get<0>(a##_##b); \ auto &b = std::get<1>(a##_##b) #define TUPLE_2D_REF(a, b, expr) \ auto &a##_##b = expr; \ auto &a = std::get<0>(a##_##b); \ auto &b = std::get<1>(a##_##b) #define TUPLE_3D(a, b, c, expr) \ decltype(expr) a##_##b##_##c = expr; \ auto &a = std::get<0>(a##_##b##_##c); \ auto &b = std::get<1>(a##_##b##_##c); \ auto &c = std::get<2>(a##_##b##_##c) #define TUPLE_3D_REF(a, b, c, expr) \ auto &a##_##b##_##c = expr; \ auto &a = std::get<0>(a##_##b##_##c); \ auto &b = std::get<1>(a##_##b##_##c); \ auto &c = std::get<2>(a##_##b##_##c) #define TUPLE_EL(a, b, expr) \ decltype(expr) a##_ = expr; \ auto &a = std::get(a##_) #define TUPLE_EL_REF(a, b, expr) \ auto &a = std::get(expr) namespace util { template