add matrix some func
This commit is contained in:
@@ -10,25 +10,22 @@ namespace hack::concepts
|
||||
{
|
||||
template<typename T>
|
||||
concept is_sequence_container = std::same_as<T, std::vector<typename T::value_type>> ||
|
||||
std::same_as<T, std::list<typename T::value_type>>;
|
||||
std::same_as<T, std::list<typename T::value_type>>;
|
||||
|
||||
template<typename T>
|
||||
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<typename T>
|
||||
concept is_string = std::is_convertible_v<T, std::string_view>;
|
||||
|
||||
template<typename T>
|
||||
concept is_map = std::same_as<T, std::map<typename T::key_type, typename T::mapped_type, typename T::key_compare, typename T::allocator_type>> ||
|
||||
std::same_as<T, std::unordered_map<typename T::key_type, typename T::mapped_type, typename T::hasher, typename T::key_equal, typename T::allocator_type>>;
|
||||
std::same_as<T, std::unordered_map<typename T::key_type, typename T::mapped_type, typename T::hasher, typename T::key_equal, typename T::allocator_type>>;
|
||||
|
||||
template<typename T>
|
||||
concept not_defined = !std::enable_if_t<!(std::integral<T> ||
|
||||
is_sequence_container<T> ||
|
||||
is_map<T> ||
|
||||
is_tuple<T> ||
|
||||
is_string<T>), bool>() == true;
|
||||
is_sequence_container<T> ||
|
||||
is_map<T> ||
|
||||
is_tuple<T> ||
|
||||
is_string<T>), bool>() == true;
|
||||
}
|
||||
|
||||
@@ -67,9 +67,34 @@ 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 vector_t = decltype(std::tuple_cat(index_t{}, std::make_tuple(T{})));
|
||||
using index_data_t = std::vector<vector_t>;
|
||||
|
||||
public:
|
||||
matrix() : local_storage_ { new index_data{} } { }
|
||||
matrix() noexcept : local_storage_ { new index_data{} } { }
|
||||
matrix(std::initializer_list<vector_t> 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<T, index_data, std::tuple<std::size_t>>{ local_storage_, std::make_tuple(index) };
|
||||
@@ -113,9 +138,6 @@ namespace hack
|
||||
private:
|
||||
struct index_data
|
||||
{
|
||||
using index_t = typename matrix_utils::generate_tuple<std::size_t, dimensions>::type;
|
||||
using index_data_t = std::vector<decltype(std::tuple_cat(index_t{}, std::make_tuple(T{})))>;
|
||||
|
||||
void set_value(const index_t& index, const T& v)
|
||||
{
|
||||
auto value = std::tuple_cat(index, std::make_tuple(v));
|
||||
|
||||
@@ -7,4 +7,5 @@ subdir('string')
|
||||
subdir('range')
|
||||
subdir('container')
|
||||
subdir('logger')
|
||||
subdir('vector')
|
||||
subdir('matrix')
|
||||
|
||||
14
src/vector/meson.build
Normal file
14
src/vector/meson.build
Normal file
@@ -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
|
||||
)
|
||||
6
src/vector/vector.hpp
Normal file
6
src/vector/vector.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace hack
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user