add matrix some func
This commit is contained in:
18
bin/main.cpp
18
bin/main.cpp
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
{// ex: matrix
|
||||
hack::matrix<int, 3> m_int;
|
||||
hack::matrix<int, 3> m_int_c;
|
||||
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;
|
||||
@@ -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<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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ deps += string_dep
|
||||
deps += range_dep
|
||||
deps += container_dep
|
||||
deps += logger_dep
|
||||
deps += vector_dep
|
||||
deps += matrix_dep
|
||||
|
||||
executable(
|
||||
|
||||
@@ -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,8 +67,33 @@ 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)
|
||||
{
|
||||
@@ -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