diff --git a/bin/main.cpp b/bin/main.cpp index e8c3aff..18ecd2b 100644 --- a/bin/main.cpp +++ b/bin/main.cpp @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) {// ex: matrix hack::matrix m_int; - hack::matrix m_int_c; + hack::matrix m_int_c { { 2, 3, 4, 123 }, { 0, 2, 4, 555 } }; hack::matrix m_float; m_int[0][0][0] = 123; @@ -86,9 +86,25 @@ int main(int argc, char *argv[]) hack::log()("m_int", i); hack::log()("m_float", f); + hack::log()("empty", m_float[123][22][33]); hack::log("")("compare (true): ", m_int == m_int_c); hack::log("")("compare (false): ", m_int == m_float); hack::log("")(m_int); + hack::log("")(m_int_c); + + auto m_moved {std::forward>(m_int_c)}; + hack::log("")("moved data: ", m_moved); + + m_int = std::forward>(m_int_c); + hack::log("")("moved data: ", m_int); + + hack::matrix m_int_d = m_int; + hack::log("")("copy data: ", m_int_d); + + hack::matrix m_int_cd { { 2, 3, 4, 3 }, { 0, 2, 4, 5 } }; + hack::log("")("copy data: ", m_int_cd); + m_int_cd = m_int; + hack::log("")("copy data: ", m_int_cd); } } diff --git a/bin/meson.build b/bin/meson.build index ab8253e..c55d514 100644 --- a/bin/meson.build +++ b/bin/meson.build @@ -5,6 +5,7 @@ deps += string_dep deps += range_dep deps += container_dep deps += logger_dep +deps += vector_dep deps += matrix_dep executable( diff --git a/src/concepts/concepts.hpp b/src/concepts/concepts.hpp index 791fbf4..2fb8ead 100644 --- a/src/concepts/concepts.hpp +++ b/src/concepts/concepts.hpp @@ -10,25 +10,22 @@ namespace hack::concepts { template concept is_sequence_container = std::same_as> || - std::same_as>; + std::same_as>; template - concept is_tuple = requires (T t) - { - std::tuple_cat(t, std::make_tuple(1, "tuple")); - }; + concept is_tuple = requires (T t) { std::tuple_cat(t, std::make_tuple(1, "tuple")); }; template concept is_string = std::is_convertible_v; template concept is_map = std::same_as> || - std::same_as>; + std::same_as>; template concept not_defined = !std::enable_if_t || - is_sequence_container || - is_map || - is_tuple || - is_string), bool>() == true; + is_sequence_container || + is_map || + is_tuple || + is_string), bool>() == true; } diff --git a/src/matrix/matrix.hpp b/src/matrix/matrix.hpp index 2244abd..cf292c7 100644 --- a/src/matrix/matrix.hpp +++ b/src/matrix/matrix.hpp @@ -67,9 +67,34 @@ namespace hack template class matrix { + using index_t = typename matrix_utils::generate_tuple::type; + using vector_t = decltype(std::tuple_cat(index_t{}, std::make_tuple(T{}))); + using index_data_t = std::vector; + public: - matrix() : local_storage_ { new index_data{} } { } + matrix() noexcept : local_storage_ { new index_data{} } { } + matrix(std::initializer_list l) noexcept : local_storage_ { new index_data{} } + { + local_storage_->values.insert(local_storage_->values.end(), l.begin(), l.end()); + } + matrix(matrix& mt) noexcept : local_storage_ { mt.local_storage_ } { } + matrix(matrix&& mt) noexcept : local_storage_ { mt.local_storage_ } { } + matrix& operator=(matrix&& mt) + { + if (this == &mt) return *this; + local_storage_.reset(); + local_storage_ = mt.local_storage_; + return *this; + } + + matrix& operator=(const matrix& mt) + { + if (this == &mt) return *this; + local_storage_ = mt.local_storage_; + return *this; + } + auto operator[](std::size_t index) { return matrix_utils::proxy>{ local_storage_, std::make_tuple(index) }; @@ -113,9 +138,6 @@ namespace hack private: struct index_data { - using index_t = typename matrix_utils::generate_tuple::type; - using index_data_t = std::vector; - void set_value(const index_t& index, const T& v) { auto value = std::tuple_cat(index, std::make_tuple(v)); diff --git a/src/meson.build b/src/meson.build index fa109f7..d03308e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,4 +7,5 @@ subdir('string') subdir('range') subdir('container') subdir('logger') +subdir('vector') subdir('matrix') diff --git a/src/vector/meson.build b/src/vector/meson.build new file mode 100644 index 0000000..5ccc04d --- /dev/null +++ b/src/vector/meson.build @@ -0,0 +1,14 @@ +headers = ['vector.hpp'] +sources = [] + +lib = library( + 'vector', + include_directories : inc, + install : true, + sources: [headers, sources] +) + +vector_dep = declare_dependency( + include_directories: inc, + link_with: lib +) diff --git a/src/vector/vector.hpp b/src/vector/vector.hpp new file mode 100644 index 0000000..4e661f9 --- /dev/null +++ b/src/vector/vector.hpp @@ -0,0 +1,6 @@ +#pragma once + + +namespace hack +{ +}