diff --git a/bin/main.cpp b/bin/main.cpp index 18ecd2b..1f369f4 100644 --- a/bin/main.cpp +++ b/bin/main.cpp @@ -11,6 +11,7 @@ #include "container/container.hpp" #include "logger/logger.hpp" #include "matrix/matrix.hpp" +#include "vector/vector.hpp" #include @@ -70,41 +71,46 @@ int main(int argc, char *argv[]) // hack::log()(v); // } - {// ex: matrix - hack::matrix m_int; - hack::matrix m_int_c { { 2, 3, 4, 123 }, { 0, 2, 4, 555 } }; - hack::matrix m_float; + // {// ex: matrix + // hack::matrix m_int; + // hack::matrix m_int_c { { 2, 3, 4, 123 }, { 0, 2, 4, 555 } }; + // hack::matrix m_float; + // + // m_int[0][0][0] = 123; + // m_int[0][0][1] = 23; + // m_int[0][0][2] = 43; + // m_int_c[0][0][0] = 123; + // m_float[0][0][0] = 123.123; + // + // auto i = m_int[0][0][0]; + // auto f = m_float[0][0][0]; + // + // 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); + // } - m_int[0][0][0] = 123; - m_int[0][0][1] = 23; - m_int[0][0][2] = 43; - m_int_c[0][0][0] = 123; - m_float[0][0][0] = 123.123; - - auto i = m_int[0][0][0]; - auto f = m_float[0][0][0]; - - 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); + {// ex: vector + hack::vector v3 { 1, 2, 3, }; + hack::log()(v3.get_value()); } } diff --git a/bin/meson.build b/bin/meson.build index c55d514..c13ffa9 100644 --- a/bin/meson.build +++ b/bin/meson.build @@ -1,5 +1,6 @@ deps += view_dep deps += concepts_dep +deps += utils_dep deps += iterators_dep deps += string_dep deps += range_dep diff --git a/src/matrix/matrix.hpp b/src/matrix/matrix.hpp index cf292c7..38c0968 100644 --- a/src/matrix/matrix.hpp +++ b/src/matrix/matrix.hpp @@ -6,20 +6,10 @@ #include #include +#include "utils/utils.hpp" + namespace hack::matrix_utils { - template - struct generate_tuple - { - using type = decltype(std::tuple_cat(typename generate_tuple::type{}, std::make_tuple(T{}))); - }; - - template - struct generate_tuple - { - using type = std::tuple; - }; - template class proxy { @@ -27,6 +17,7 @@ namespace hack::matrix_utils public: proxy(const std::weak_ptr& local_storage, const index_t& index) : local_storage_ { local_storage }, index_ { index } {}; + ~proxy() = default; auto operator[](std::size_t index) const { @@ -67,7 +58,7 @@ namespace hack template class matrix { - using index_t = typename matrix_utils::generate_tuple::type; + using index_t = typename utils::generate_tuple::type; using vector_t = decltype(std::tuple_cat(index_t{}, std::make_tuple(T{}))); using index_data_t = std::vector; @@ -79,6 +70,7 @@ namespace hack } matrix(matrix& mt) noexcept : local_storage_ { mt.local_storage_ } { } matrix(matrix&& mt) noexcept : local_storage_ { mt.local_storage_ } { } + ~matrix() = default; matrix& operator=(matrix&& mt) { diff --git a/src/meson.build b/src/meson.build index d03308e..f2b0581 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,6 +2,7 @@ inc += include_directories('.') subdir('view') subdir('concepts') +subdir('utils') subdir('iterators') subdir('string') subdir('range') diff --git a/src/utils/meson.build b/src/utils/meson.build new file mode 100644 index 0000000..acd61a7 --- /dev/null +++ b/src/utils/meson.build @@ -0,0 +1,14 @@ +headers = ['utils.hpp'] +sources = [] + +lib = library( + 'utils', + include_directories : inc, + install : true, + sources: [headers, sources] +) + +utils_dep = declare_dependency( + include_directories: inc, + link_with: lib +) diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp new file mode 100644 index 0000000..b671127 --- /dev/null +++ b/src/utils/utils.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace hack::utils +{ + template + struct generate_tuple + { + using type = decltype(std::tuple_cat(typename generate_tuple::type{}, std::make_tuple(T{}))); + }; + + template + struct generate_tuple + { + using type = std::tuple; + }; +} diff --git a/src/vector/vector.hpp b/src/vector/vector.hpp index 4e661f9..81753d8 100644 --- a/src/vector/vector.hpp +++ b/src/vector/vector.hpp @@ -1,6 +1,36 @@ #pragma once +#include + +namespace hack +{ + template + struct generate_tuple + { + using type = decltype(std::tuple_cat(std::make_tuple(T{}), typename generate_tuple::type{})); + }; + + template + struct generate_tuple + { + using type = std::tuple; + }; +} namespace hack { + template + class vector + { + using value_t = decltype(typename generate_tuple::type{}); + + public: + vector(Args... args) : value_ { args... } {} + + public: + value_t get_value() { return value_; }; + + private: + value_t value_; + }; }