#ifndef GUARD_RTGLIB_LITERAL_HPP #define GUARD_RTGLIB_LITERAL_HPP #include #include #include #include namespace rtg { struct literal : raw_data { literal() : buffer(), shape_() {} template literal(T x) : buffer(sizeof(T), 0), shape_(shape::get_type{}) { static_assert(std::is_trivial{}, "Literals can only be trivial types"); *(reinterpret_cast(buffer.data())) = x; } template literal(shape s, const std::vector& x) : buffer(s.bytes(), 0), shape_(s) { assert(s.packed()); static_assert(std::is_trivial{}, "Literals can only be trivial types"); std::copy(x.begin(), x.end(), reinterpret_cast(buffer.data())); } template literal(shape s, const std::initializer_list& x) : buffer(s.bytes(), 0), shape_(s) { assert(s.packed()); static_assert(std::is_trivial{}, "Literals can only be trivial types"); std::copy(x.begin(), x.end(), reinterpret_cast(buffer.data())); } literal(shape s, const char* x) : buffer(x, x+s.bytes()), shape_(s) {} bool empty() const { return this->buffer.empty(); } const char* data() const { return this->buffer.data(); } const shape& get_shape() const { return this->shape_; } argument get_argument() const { auto b = buffer; return {shape_, [b]() mutable { return b.data(); }}; } private: std::vector buffer; shape shape_; }; } #endif