run vector

This commit is contained in:
chatlanin
2022-03-24 13:04:27 +03:00
parent 2ae61bbb07
commit 94b734647e
7 changed files with 111 additions and 48 deletions

View File

@@ -11,6 +11,7 @@
#include "container/container.hpp"
#include "logger/logger.hpp"
#include "matrix/matrix.hpp"
#include "vector/vector.hpp"
#include <string_view>
@@ -70,41 +71,46 @@ int main(int argc, char *argv[])
// hack::log()(v);
// }
{// ex: matrix
hack::matrix<int, 3> m_int;
hack::matrix<int, 3> m_int_c { { 2, 3, 4, 123 }, { 0, 2, 4, 555 } };
hack::matrix<float, 3> m_float;
// {// ex: matrix
// hack::matrix<int, 3> m_int;
// hack::matrix<int, 3> m_int_c { { 2, 3, 4, 123 }, { 0, 2, 4, 555 } };
// hack::matrix<float, 3> 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<hack::matrix<int, 3>>(m_int_c)};
// hack::log("")("moved data: ", m_moved);
//
// m_int = std::forward<hack::matrix<int, 3>>(m_int_c);
// hack::log("")("moved data: ", m_int);
//
// hack::matrix<int, 3> m_int_d = m_int;
// hack::log("")("copy data: ", m_int_d);
//
// hack::matrix<int, 3> 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<hack::matrix<int, 3>>(m_int_c)};
hack::log("")("moved data: ", m_moved);
m_int = std::forward<hack::matrix<int, 3>>(m_int_c);
hack::log("")("moved data: ", m_int);
hack::matrix<int, 3> m_int_d = m_int;
hack::log("")("copy data: ", m_int_d);
hack::matrix<int, 3> 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<int, int, int> v3 { 1, 2, 3, };
hack::log()(v3.get_value());
}
}

View File

@@ -1,5 +1,6 @@
deps += view_dep
deps += concepts_dep
deps += utils_dep
deps += iterators_dep
deps += string_dep
deps += range_dep

View File

@@ -6,20 +6,10 @@
#include <algorithm>
#include <iostream>
#include "utils/utils.hpp"
namespace hack::matrix_utils
{
template<typename T, size_t N>
struct generate_tuple
{
using type = decltype(std::tuple_cat(typename generate_tuple<T, N - 1>::type{}, std::make_tuple(T{})));
};
template<typename T>
struct generate_tuple<T, 1>
{
using type = std::tuple<T>;
};
template<typename T,typename index_data, typename index_t>
class proxy
{
@@ -27,6 +17,7 @@ namespace hack::matrix_utils
public:
proxy(const std::weak_ptr<index_data>& 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<typename T, std::size_t dimensions>
class matrix
{
using index_t = typename matrix_utils::generate_tuple<std::size_t, dimensions>::type;
using index_t = typename utils::generate_tuple<std::size_t, dimensions>::type;
using vector_t = decltype(std::tuple_cat(index_t{}, std::make_tuple(T{})));
using index_data_t = std::vector<vector_t>;
@@ -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)
{

View File

@@ -2,6 +2,7 @@ inc += include_directories('.')
subdir('view')
subdir('concepts')
subdir('utils')
subdir('iterators')
subdir('string')
subdir('range')

14
src/utils/meson.build Normal file
View File

@@ -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
)

19
src/utils/utils.hpp Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <iostream>
#include <unordered_map>
namespace hack::utils
{
template<typename T, size_t N>
struct generate_tuple
{
using type = decltype(std::tuple_cat(typename generate_tuple<T, N - 1>::type{}, std::make_tuple(T{})));
};
template<typename T>
struct generate_tuple<T, 1>
{
using type = std::tuple<T>;
};
}

View File

@@ -1,6 +1,36 @@
#pragma once
#include <tuple>
namespace hack
{
template<typename T, typename... Args>
struct generate_tuple
{
using type = decltype(std::tuple_cat(std::make_tuple(T{}), typename generate_tuple<Args...>::type{}));
};
template<typename T>
struct generate_tuple<T>
{
using type = std::tuple<T>;
};
}
namespace hack
{
template<typename... Args>
class vector
{
using value_t = decltype(typename generate_tuple<Args...>::type{});
public:
vector(Args... args) : value_ { args... } {}
public:
value_t get_value() { return value_; };
private:
value_t value_;
};
}