diff --git a/include/rfl/Array.hpp b/include/rfl/Array.hpp index 7e4f931e..88059b64 100644 --- a/include/rfl/Array.hpp +++ b/include/rfl/Array.hpp @@ -16,8 +16,6 @@ struct Array { Array() = default; Array(const StdArrayType &_arr) : arr_(_arr) {} Array(StdArrayType &&_arr) : arr_(std::move(_arr)) {} - Array(const T &_t) : arr_(reinterpret_cast(_t)) {} - Array(T &&_t) : arr_(reinterpret_cast(_t)) {} ~Array() = default; diff --git a/include/rfl/internal/move_from_tuple.hpp b/include/rfl/internal/move_from_tuple.hpp index f10bebd8..6bda97a2 100644 --- a/include/rfl/internal/move_from_tuple.hpp +++ b/include/rfl/internal/move_from_tuple.hpp @@ -83,22 +83,48 @@ auto move_from_pointers(Pointers& _ptrs, Args&&... _args) { } } -template -auto make_tuple_from_element(T (*arr)[n]) { - if constexpr (std::is_array_v) { +template +struct is_std_array : public std::false_type {}; + +template +struct is_std_array> : public std::true_type {}; + +template +constexpr bool is_std_array_v = is_std_array::value; + +template +auto make_tuple_from_element(T (*_arr)[_n]) { + if constexpr (std::is_array_v || is_std_array_v) { return [&](std::index_sequence) { - return std::tuple_cat(make_tuple_from_element(&(*arr)[i])...); - }(std::make_index_sequence()); + return std::tuple_cat(make_tuple_from_element(&(*_arr)[i])...); + } + (std::make_index_sequence<_n>()); } else { return [&](std::index_sequence) { - return std::make_tuple(&(*arr)[i]...); - }(std::make_index_sequence()); + return std::make_tuple(&(*_arr)[i]...); + } + (std::make_index_sequence<_n>()); + } +} + +template +auto make_tuple_from_element(std::array* _arr) { + if constexpr (std::is_array_v || is_std_array_v) { + return [&](std::index_sequence) { + return std::tuple_cat(make_tuple_from_element(&(*_arr)[i])...); + } + (std::make_index_sequence<_n>()); + } else { + return [&](std::index_sequence) { + return std::make_tuple(&(*_arr)[i]...); + } + (std::make_index_sequence<_n>()); } } template -auto make_tuple_from_element(Array* arr) { - return make_tuple_from_element(reinterpret_cast(arr)); +auto make_tuple_from_element(Array* _arr) { + return make_tuple_from_element(&(_arr->arr_)); } auto make_tuple_from_element(auto& e) { return std::make_tuple(e); } @@ -106,8 +132,9 @@ auto make_tuple_from_element(auto& e) { return std::make_tuple(e); } auto flatten_c_arrays(const auto& tuple) { return [&](std::index_sequence) { return std::tuple_cat(make_tuple_from_element(std::get(tuple))...); - }(std::make_index_sequence< - std::tuple_size_v>>()); + } + (std::make_index_sequence< + std::tuple_size_v>>()); } /// Creates a struct of type T from a tuple by moving the underlying diff --git a/include/rfl/xml/OutputValue.hpp b/include/rfl/xml/OutputValue.hpp deleted file mode 100644 index c03defa5..00000000 --- a/include/rfl/xml/OutputValue.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef RFL_XML_OUTPUTVALUE_HPP_ -#define RFL_XML_OUTPUTVALUE_HPP_ - -#include -#include -#include - -#include "../always_false.hpp" -#include "OutputVar.hpp" - -namespace rfl { -namespace xml { - -template -class OutputValue : public OutputVar { - public: - static constexpr const char* XML_CONTENT = "xml_content"; - - public: - OutputValue(T _val, bool _is_attribute) - : is_attribute_(_is_attribute), val_(_val) {} - - ~OutputValue() = default; - - /// Inserts all elements into the builder. - void insert(const std::string& _key, pugi::xml_node* _parent) final { - const auto str = to_string(); - if (is_attribute_) { - _parent->append_attribute(_key.c_str()) = str.c_str(); - } else if (_key == XML_CONTENT) { - _parent->append_child(pugi::node_pcdata).set_value(str.c_str()); - } else { - auto node_child = _parent->append_child(_key.c_str()); - node_child.append_child(pugi::node_pcdata).set_value(str.c_str()); - } - }; - - /// Whether this is null. - bool is_null() const final { return false; } - - private: - /// Transforms the underlying value into a string. - std::string to_string() { - if constexpr (std::is_same, std::string>()) { - return val_; - } else if constexpr (std::is_same, bool>()) { - return val_ ? "true" : "false"; - } else if constexpr (std::is_floating_point>() || - std::is_integral>()) { - return std::to_string(val_); - } else { - static_assert(always_false_v, "Unsupported type"); - } - } - - private: - /// Whether you want this encoded as an attribute. - bool is_attribute_; - - /// The underlying value. - T val_; -}; - -} // namespace xml -} // namespace rfl - -#endif