run vector
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
14
src/utils/meson.build
Normal 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
19
src/utils/utils.hpp
Normal 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>;
|
||||
};
|
||||
}
|
||||
@@ -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_;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user