diff --git a/bin/concepts/main.cpp b/bin/concepts/main.cpp new file mode 100644 index 0000000..bce490e --- /dev/null +++ b/bin/concepts/main.cpp @@ -0,0 +1,31 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/concepts/concepts.hpp" + +template +void test_map(const T& m) +{ + hack::log()("is map", m); +} + +template +void test_associative(const T& m) +{ + hack::log()("is associative", m); +} + +auto main(int argc, char *argv[]) -> int +{ + std::map m { { "a", 1 }, { "b", 2 } }; + test_map(m); + test_associative(m); + + auto t = std::make_tuple("a", 1, "b", 2); + test_associative(t); + + std::vector v { 1, 2, 3 }; + // test_associative(v); error !!! +} + + diff --git a/bin/containers/main.cpp b/bin/containers/main.cpp new file mode 100644 index 0000000..7269744 --- /dev/null +++ b/bin/containers/main.cpp @@ -0,0 +1,40 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/containers/containers.hpp" + +auto main(int argc, char *argv[]) -> int +{ + hack::log()("============================================================"); + hack::log()("container::vector_multiset"); + + {// ex: containers::vector + std::vector v; + hack::containers::vector::multiset(v, "asdf", "qwer", "zcv"); + hack::log()(v); + + hack::containers::vector::remove_at(v, 1); + hack::log()(v); + + hack::containers::vector::multiset(v, "aa", "bb", "cc"); + hack::log()(v); + + auto it = std::find(v.begin(), v.end(), "aa"); + hack::log()(*it); + hack::containers::vector::remove_at(v, it); + hack::log()(v); + } + + {// ex: containers::utils::count + std::vector v { "aa", "bb", "cc" }; + auto r = hack::containers::utils::count(v, "aa", "bb"); + hack::log()(r); + } + + {// ex: containers::set + std::set s; + hack::containers::set::multiset(s, 1, 2, 3); + hack::warn()("TODO: реализовать в log вывод set контейнера!"); + } +} + diff --git a/bin/iterators/main.cpp b/bin/iterators/main.cpp new file mode 100644 index 0000000..fc3d4ba --- /dev/null +++ b/bin/iterators/main.cpp @@ -0,0 +1,25 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/iterators/associative_ostream_iterator.hpp" +#include "hack/concepts/concepts.hpp" + +template +static void print_t(const T& data) +{ + std::cout << "{"; + std::copy(data.cbegin(), data.cend(), hack::iterators::associative_ostream_iterator(data.size(), std::cout)); + std::cout << "}"; +} + +auto main(int argc, char *argv[]) -> int +{ + std::map m { { "a", 1 }, { "b", 2 } }; + + for (auto& [key, value] : m) + hack::log()(key, value); + + print_t(m); +} + + diff --git a/bin/logger/main.cpp b/bin/logger/main.cpp new file mode 100644 index 0000000..951e574 --- /dev/null +++ b/bin/logger/main.cpp @@ -0,0 +1,14 @@ +#include + +#include "hack/logger/logger.hpp" + +auto main(int argc, char *argv[]) -> int +{ + std::set s { 1, 2, 3 }; + hack::log()(s); + + std::vector v { 1, 2, 3 }; + hack::log()(v, s); +} + + diff --git a/bin/macros/main.cpp b/bin/macros/main.cpp new file mode 100644 index 0000000..501fb4a --- /dev/null +++ b/bin/macros/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/macros/macros.hpp" + +auto main(int argc, char *argv[]) -> int +{ + std::string s { MAKE_STR(test) }; + hack::log()(s); +} + + diff --git a/bin/main.cpp b/bin/main.cpp deleted file mode 100755 index cc10be3..0000000 --- a/bin/main.cpp +++ /dev/null @@ -1,351 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include - -#include "hack/string/string.hpp" -#include "hack/string/string_concat_helper.hpp" -#include "hack/range/range.hpp" -#include "hack/container/container.hpp" -#include "hack/logger/logger.hpp" -#include "hack/math/matrix.hpp" -#include "hack/math/vector.hpp" -#include "hack/utils/utils.hpp" -#include "hack/utils/func_query.hpp" -#include "hack/security/validate_email.hpp" -#include "hack/security/uuid.hpp" -#include "hack/security/is_string.hpp" -#include "hack/security/is_link.hpp" -#include "hack/string/utf8_len.hpp" -#include "hack/macros/macros.hpp" - -// for example -int f(int a) -{ - hack::log()("f implementatioln"); - return ++a; -} - -int plus(int a) -{ - return ++a; -} - -int minus(int a) -{ - return --a; -} - -struct ForTypeTrace -{ - int a; -}; - -struct counter_test -{ - counter_test() : id { ++hack::utils::counter::id } { } - int id; -}; - -struct counter_test_2 -{ - counter_test_2() : id { ++hack::utils::counter::id } { } - int id; -}; - -int main(int argc, char *argv[]) -{ - hack::log()("string::split_str"); - {// ex: string::split_str - std::string str { "asdf,qwer,zxcv" }; - std::string str_int { "1 2 3" }; - hack::string::v_str v = hack::string::split_str(str, ','); - auto v_int = hack::string::split_stoi(str_int, ' '); - hack::log log; - for (const auto& c : v) log(c); - for (const auto& c : v_int) log(c); - - std::string str_2 { "qqq,aaa:eee,ggg" }; - hack::string::v_str v_2 = hack::string::split_str(str_2, ",:"); - for (const auto& c : v_2) log(c); - } - - hack::log()("============================================================"); - hack::log()("range::within"); - - {// ex: renge::within - hack::log()(hack::range::within(12, 34, 12, 23, 31, 17, 22, 33)); - } - - hack::log()("============================================================"); - hack::log()("container::vector_multiset"); - - {// ex: container::vector_multiset - std::vector v; - hack::container::vector_multiset(v, "asdf", "qwer", "zcv"); - // of course you understand that a new logger object is created here every time !!! - for(const auto& c : v) hack::log()(c); - hack::log()(v); - } - - hack::log()("============================================================"); - hack::log()("container::set_multiset"); - - {// ex: container::set_multiset - std::set s; - hack::container::set_multiset(s, 1, 2, 3, 3, 2, 1); - for(const auto& c : s) hack::log()(c); - } - - hack::log()("============================================================"); - hack::log()("logger::log"); - - {// ex: logger::log - int a = 10; - ForTypeTrace ftt { 1234 }; - hack::log::type_trace(a, a, ftt); - hack::log()(1234, "run in main", 1234); - hack::warn(" # ")(1234, "run in main", 1234); - hack::error(" - ")(1234, "run in main", 1234); - - std::string str { "hi" }; - hack::log()(str); - - std::vector vs { "asdf", "qwer", "zxcv" }; - hack::log()("vector", vs, 1, 2, 'a'); - - std::list ls { "asdf", "qwer", "zxcv" }; - hack::log()(vs, ls); - - std::map m { { 1, "asdf" }, { 2, "qwer" }, { 3, "zxcv" } }; - hack::log()(vs, ls, m); - - std::tuple tp { 1, "tuple test", false }; - hack::log()(tp); - } - - hack::log()("============================================================"); - hack::log()("container::matches"); - - {// ex: container::matches - std::vector v { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - hack::log()(hack::container::matches(v, 2, 5, 4, 12)); - } - - hack::log()("============================================================"); - hack::log()("container::vector_remove_at"); - - {// ex: container::vector_remove_at - std::vector v { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - hack::container::vector_remove_at(v, 3); - hack::log()(v); - } - - hack::log()("============================================================"); - hack::log()("math::matrix"); - - {// ex: math::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); - } - - hack::log()("============================================================"); - hack::log()("math::vector"); - - {// ex: math::vector - hack::vector v3_1 { 8, 4, 9, }; - hack::vector v3_2 { 1, 2, 3, }; - hack::log()(v3_1.get_value()); - hack::log()(v3_2.get_value()); - - v3_1 = v3_2; - - hack::log()(v3_1.get_value()); - hack::log()(v3_2.get_value()); - - hack::log()("length 3", v3_2.length()); - - hack::vector v2_1 { 11, 22 }; - hack::log()("length 2", v2_1.length()); - - hack::vector lerp_1 { 1, 2, 3 }; - hack::vector lerp_2 { 5, 6, 7 }; - hack::log()("lerp", lerp_1.lerp(lerp_2, 0.75f)); - - auto [x, y, z] = lerp_1.get_value(); - hack::log()("get", x, y, z); - hack::log()("get", lerp_1.x()); - } - - hack::log()("============================================================"); - hack::log()("utils::func_memory"); - - {// ex: utils::func_memory - auto cach_f = hack::utils::func_memory(f); - hack::log()("result 1", cach_f(12)); - hack::log()("result 2", cach_f(12)); - } - - hack::log()("============================================================"); - hack::log()("string::str_concat"); - - {// ex: string::str_concat - std::string name = "tro"; - std::string surname = "lolo"; - const auto full_name = hack::string::str_concat + name + ", " + surname; - hack::log()(full_name); - hack::log()(hack::string::str_concat + "super", + "string"); - } - - hack::log()("============================================================"); - hack::log()("utils::func_concat"); - - {// ex: utils::func_concat - auto combine ( hack::utils::func_concat(plus, minus) ); - hack::log("")("func_concat result: ", combine(3)); - } - - hack::log()("============================================================"); - hack::log()("utils::exec"); - - {// ex: utils::exec - hack::log()(hack::utils::unix_cmd("ls")); - hack::log()(hack::utils::unix_cmd("pwd")); - auto t = hack::utils::unix_cmd("pwd"); - hack::log::type_trace(t); - } - - hack::log()("============================================================"); - hack::log()("security::validate_email"); - - {// ex: security::validate_email - std::string email = "asdf@asdf.com"; - hack::log()(hack::security::validate_email(email)); - } - - hack::log()("============================================================"); - hack::log()("security::generate_uuid"); - - {// ex: security::generate_uuid - auto uuid = hack::security::generate_uuid(); - hack::log()(uuid, hack::security::validate_uuid(uuid)); - } - - hack::log()("============================================================"); - hack::log()("security::is_string"); - - {// ex: security::is_string - std::string s {"test"}; - hack::log()(hack::security::is_string::value); - hack::log()(hack::security::is_string::value); - hack::log()(hack::security::is_string::value); - hack::log()(hack::security::is_string::value); - hack::log()(hack::security::is_string::value); - } - - hack::log()("============================================================"); - hack::log()("utils::counter"); - - {// ex: counter - counter_test a, b, c; - counter_test_2 a1, b1, c1; - hack::log()(c.id); - hack::log()(c1.id); - } - - {// ex: case as string - switch(hack::utils::case_int("test")) - { - case hack::utils::case_int("test"): hack::log()("wow"); break; - case hack::utils::case_int("no_test"): hack::log()("ups"); break; - } - } - - hack::log()("============================================================"); - hack::log()("utils::make_query"); - - {// ex: query function - auto query = hack::utils::make_query("super_function", "1", "two"); - hack::log()("query", query); - - query = hack::utils::make_query("super_function", 1, 'c'); - hack::log()("query", query); - - hack::utils::JSON js { "test", "data" }; - query = hack::utils::make_query("super_function", 1, 123.3f, js); - hack::log()("query", query); - - query = hack::utils::make_query("super_function"); - hack::log()("query", query); - } - - hack::log()("============================================================"); - hack::log()("utils::is_link"); - - {// ex: is link - std::string link { "https://google.com" }; - if (hack::security::is_link(link)) - hack::log()("is link"); - - link = "https//google.com"; - if (!hack::security::is_link(link)) - hack::error()("no link"); - } - - hack::log()("============================================================"); - hack::log()("string::utf8_size"); - - {// ex: utf8_size - std::string str = "hi hi"; - auto s = hack::string::utf8_len(str); - hack::log()(s); - - s = hack::string::utf8_len("asdf"); - hack::log()(s); - } - - hack::log()("============================================================"); - hack::log()("macros"); - - {// ex: macros make_string - std::string s { MAKE_STR(test string) }; - hack::log()(s); - } -} diff --git a/bin/memory/main.cpp b/bin/memory/main.cpp new file mode 100644 index 0000000..b2cf024 --- /dev/null +++ b/bin/memory/main.cpp @@ -0,0 +1,16 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/memory/make_ptr.hpp" + +auto main(int argc, char *argv[]) -> int +{ + auto a = hack::memory::make_unique(5); + hack::log()(*a); + + auto arr = hack::memory::make_unique(5); + arr[0] = 1; + hack::log()(arr[0]); +} + + diff --git a/bin/meson.build b/bin/meson.build index d948b43..658b058 100755 --- a/bin/meson.build +++ b/bin/meson.build @@ -1,6 +1,6 @@ executable( 'hack', - 'main.cpp', + 'utils/main.cpp', dependencies : deps, cpp_args: args, include_directories : inc diff --git a/bin/security/main.cpp b/bin/security/main.cpp new file mode 100644 index 0000000..d7dca94 --- /dev/null +++ b/bin/security/main.cpp @@ -0,0 +1,25 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/security/uuid.hpp" +#include "hack/security/is_link.hpp" +#include "hack/security/is_string.hpp" +#include "hack/security/validate_email.hpp" + +auto main(int argc, char *argv[]) -> int +{ + auto uuid = hack::security::generate_uuid(); + hack::log()(uuid); + + hack::log()(hack::security::validate_uuid(uuid)); + + std::string url = "https://google.com"; + hack::log()(hack::security::is_link(url)); + + hack::log()(hack::security::is_string::value); + + std::string email = "asdf@asdf.com"; + hack::log()(hack::security::validate_email(email));; +} + + diff --git a/bin/string/main.cpp b/bin/string/main.cpp new file mode 100644 index 0000000..32d60c6 --- /dev/null +++ b/bin/string/main.cpp @@ -0,0 +1,42 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/string/string.hpp" +#include "hack/string/string_concat_helper.hpp" +#include "hack/string/utf8_len.hpp" + +auto main(int argc, char *argv[]) -> int +{ + {// ex: split string + std::string str { "asdf,qwer,zxcv" }; + std::string str_int { "1 2 3" }; + hack::string::v_str v = hack::string::split_str(str, ','); + auto v_int = hack::string::split_stoi(str_int, ' '); + hack::log log; + for (const auto& c : v) log(c); + for (const auto& c : v_int) log(c); + + std::string str_2 { "qqq,aaa:eee,ggg" }; + hack::string::v_str v_2 = hack::string::split_str(str_2, ",:"); + for (const auto& c : v_2) log(c); + } + + {// ex: string::str_concat + std::string name = "tro"; + std::string surname = "lolo"; + const auto full_name = hack::string::str_concat + name + ", " + surname; + hack::log()(full_name); + hack::log()(hack::string::str_concat + "super", + "string"); + } + + {// ex: utf8_size + std::string str = "hi hi"; + auto s = hack::string::utf8_len(str); + hack::log()(s); + + s = hack::string::utf8_len("asdf"); + hack::log()(s); + } +} + + diff --git a/bin/utils/main.cpp b/bin/utils/main.cpp new file mode 100644 index 0000000..eefcefd --- /dev/null +++ b/bin/utils/main.cpp @@ -0,0 +1,88 @@ +#include + +#include "hack/logger/logger.hpp" +#include "hack/utils/utils.hpp" +#include "hack/utils/func_query.hpp" + +int f(int a) +{ + hack::log()("f implementatioln"); + return ++a; +} + +int plus(int a) +{ + return ++a; +} + +int minus(int a) +{ + return --a; +} + +struct counter_test +{ + counter_test() : id { ++hack::utils::counter::id } { } + int id; +}; + +struct counter_test_2 +{ + counter_test_2() : id { ++hack::utils::counter::id } { } + int id; +}; + +auto main(int argc, char *argv[]) -> int +{ + {// ex: utils::func_memory + int a = 12; + auto cach_f = hack::utils::func_memory(f); + hack::log()("result 1", cach_f(a)); + hack::log()("result 2", cach_f(a)); + } + + {// ex: utils::func_concat + int a = 1; + auto combine ( hack::utils::func_concat(plus, minus, plus, f) ); + hack::log("")("func_concat result: ", combine(a), a); + } + + {// ex: utils::exec + hack::log()(hack::utils::unix_cmd("ls")); + hack::log()(hack::utils::unix_cmd("pwd")); + auto t = hack::utils::unix_cmd("pwd"); + hack::log::type_trace(t); + } + + {// ex: counter + counter_test a, b, c; + counter_test_2 a1, b1, c1; + hack::log()(c.id); + hack::log()(c1.id); + } + + {// ex: case as string + switch(hack::utils::case_int("test")) + { + case hack::utils::case_int("test"): hack::log()("wow"); break; + case hack::utils::case_int("no_test"): hack::log()("ups"); break; + } + } + + {// ex: query function + auto query = hack::utils::make_query("super_function", "1", "two"); + hack::log()("query", query); + + query = hack::utils::make_query("super_function", 1, 'c'); + hack::log()("query", query); + + hack::utils::JSON js { "test", "data" }; + query = hack::utils::make_query("super_function", 1, 123.3f, js); + hack::log()("query", query); + + query = hack::utils::make_query("super_function"); + hack::log()("query", query); + } +} + + diff --git a/meson.build b/meson.build index 0fb867a..3f8e9e9 100755 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project( 'hack', 'cpp', - version: '1.0.0', + version: '1.1.0', default_options : [ 'warning_level=1', 'optimization=3', @@ -21,6 +21,7 @@ add_project_arguments ( '-Wno-narrowing', '-Wno-deprecated-enum-enum-conversion', '-Wno-volatile', + '-Wno-modernize-concat-nested-namespaces', language: 'cpp' ) diff --git a/src/hack/concepts/concepts.hpp b/src/hack/concepts/concepts.hpp index 2fb8ead..c365927 100755 --- a/src/hack/concepts/concepts.hpp +++ b/src/hack/concepts/concepts.hpp @@ -4,28 +4,40 @@ #include #include #include +#include #include +#include + namespace hack::concepts { template - concept is_sequence_container = std::same_as> || - std::same_as>; + concept is_map = std::same_as> || + std::same_as>; template concept is_tuple = requires (T t) { std::tuple_cat(t, std::make_tuple(1, "tuple")); }; template - concept is_string = std::is_convertible_v; + concept is_set = std::same_as>; template - concept is_map = std::same_as> || - std::same_as>; + concept is_string = std::is_convertible_v; + + template + concept is_sequence_container = std::same_as> || std::same_as> || (std::is_array_v && N > 0); + + template + concept is_associative_container = is_map || is_tuple || is_set; + template concept not_defined = !std::enable_if_t || is_sequence_container || is_map || is_tuple || + is_set || + std::is_array() || is_string), bool>() == true; + } diff --git a/src/hack/container/container.hpp b/src/hack/container/container.hpp deleted file mode 100755 index e5eaa29..0000000 --- a/src/hack/container/container.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include -#include - -namespace hack::container -{ - template - void vector_multiset(Range& r, Args... args) - { - constexpr std::size_t t = sizeof... (args); - r.reserve(t); - (r.emplace_back(std::forward(args)), ...); - } - - template - void set_multiset(Range& r, Args... args) - { - (r.insert(args), ...); - } - - template - int matches(Range r, Args... args) - { - return (std::count(std::cbegin(r), std::cend(r), args) + ...); - } - - // ----------------------------------------------------- - // remove vector element if vector sorting no important - template - void vector_remove_at(std::vector& v, std::size_t idx) - { - if (idx < v.size()) - { - v[idx] = std::move(v.back()); - v.pop_back(); - } - } - - template - void vector_remove_at(std::vector& v, typename std::vector::iterator it) - { - if (it != v.end()) - { - *it = std::move(v.back()); - v.pop_back(); - } - } - // ----------------------------------------------------- -} diff --git a/src/hack/containers/containers.hpp b/src/hack/containers/containers.hpp new file mode 100644 index 0000000..8f854fd --- /dev/null +++ b/src/hack/containers/containers.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include "vector.hpp" +#include "utils.hpp" +#include "set.hpp" diff --git a/src/hack/containers/set.hpp b/src/hack/containers/set.hpp new file mode 100755 index 0000000..a65ca69 --- /dev/null +++ b/src/hack/containers/set.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace hack::containers::set +{ + // множественная вставка элементов + template + void multiset(Range& r, Args... args) + { + (r.insert(args), ...); + } +} diff --git a/src/hack/containers/utils.hpp b/src/hack/containers/utils.hpp new file mode 100755 index 0000000..5a5aac2 --- /dev/null +++ b/src/hack/containers/utils.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +namespace hack::containers::utils +{ + // подсчитывает кол-во присутствующих элементов в диапозоне + template + int count(Range r, Args... args) + { + return (std::count(std::cbegin(r), std::cend(r), args) + ...); + } +} diff --git a/src/hack/containers/vector.hpp b/src/hack/containers/vector.hpp new file mode 100755 index 0000000..d987fec --- /dev/null +++ b/src/hack/containers/vector.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +namespace hack::containers::vector +{ + // множественная вставка элементов + template + void multiset(Range& r, Args... args) + { + constexpr std::size_t t = sizeof... (args); + r.reserve(t); + (r.emplace_back(std::forward(args)), ...); + } + + // удаление элемента вектора по его индексу, если не важна сортировка + template + void remove_at(std::vector& v, std::size_t idx) + { + if (idx < v.size()) + { + v[idx] = std::move(v.back()); + v.pop_back(); + } + } + + // удаление элемента вектора по его итератору, если не важна сортировка + template + void remove_at(std::vector& v, typename std::vector::iterator it) + { + if (it != v.end()) + { + *it = std::move(v.back()); + v.pop_back(); + } + } +} diff --git a/src/hack/iterators/associative_ostream_iterator.hpp b/src/hack/iterators/associative_ostream_iterator.hpp index 7834660..223d19a 100755 --- a/src/hack/iterators/associative_ostream_iterator.hpp +++ b/src/hack/iterators/associative_ostream_iterator.hpp @@ -19,7 +19,7 @@ namespace hack::iterators public: associative_ostream_iterator(std::size_t size, ostream_type& os) : os_ { &os }, size_ { size } { } - auto& operator=(T const& item) + auto& operator=(const T& item) { --size_; const auto& [key, value] = item; diff --git a/src/hack/logger/logger.hpp b/src/hack/logger/logger.hpp index b54fd06..4248f10 100755 --- a/src/hack/logger/logger.hpp +++ b/src/hack/logger/logger.hpp @@ -9,7 +9,6 @@ #include "hack/iterators/sequence_ostream_iterator.hpp" #include "hack/iterators/associative_ostream_iterator.hpp" #include "hack/math/matrix.hpp" -// #include "nlohmann/json.hpp" namespace hack { @@ -67,7 +66,7 @@ namespace hack template static void print(const T& data, const Args&... args) { - count--; + --count; print_t(data); print(args...); } @@ -92,6 +91,14 @@ namespace hack std::cout << " }" << (count != 0 ? devider : ""); } + template + static void print_t(const T& data) + { + std::cout << "{ "; + std::copy(data.cbegin(), data.cend(), iterators::sequence_ostream_iterator(data.size(), std::cout)); + std::cout << " }" << (count != 0 ? devider : ""); + } + template static void print_t(const T& data) { @@ -120,7 +127,7 @@ namespace hack std::size_t index = data.size(); for (auto& r : data) { - index--; + --index; std::cout << "{ "; print_t(std::get(r)); std::cout << " }" << (index != 0 ? ", " : ""); diff --git a/src/hack/math/max.hpp b/src/hack/math/max.hpp index 54ab845..bac525e 100755 --- a/src/hack/math/max.hpp +++ b/src/hack/math/max.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace hack { @@ -10,6 +11,6 @@ namespace hack template> inline RT max(T a, U b) { - return a > b ? a : b; + return std::max(a, b); } } diff --git a/src/hack/memory/make_ptr.hpp b/src/hack/memory/make_ptr.hpp new file mode 100644 index 0000000..ca8ada9 --- /dev/null +++ b/src/hack/memory/make_ptr.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "hack/concepts/concepts.hpp" + +namespace hack::memory +{ + // обсуждение тут: https://stackoverflow.com/questions/10149840/c-arrays-and-make-unique + template + typename std::enable_if::value, std::unique_ptr>::type make_unique(Args &&...args) + { + return std::unique_ptr(new T(std::forward(args)...)); + } + + template + typename std::enable_if::value, std::unique_ptr>::type make_unique(std::size_t n) + { + using RT = typename std::remove_extent::type; + return std::unique_ptr(new RT[n]); + } +} diff --git a/src/hack/range/range.hpp b/src/hack/range/range.hpp deleted file mode 100755 index 5ef9e4c..0000000 --- a/src/hack/range/range.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace hack::range -{ - // являются ли числа максимум и минимум последовательности - template - bool within(const T min, const T max, Args... args) - { - // 1, 5, 2, 3, 4 - // ( (1 <= 2 && 5 >= 2) && (1 <= 3 && 5 >= 3) && (1 <= 4 && 5 >= 4) ) - return ((min <= args && max >= args) && ...); - } -} diff --git a/src/hack/utils/utils.hpp b/src/hack/utils/utils.hpp index b436565..1ac065e 100755 --- a/src/hack/utils/utils.hpp +++ b/src/hack/utils/utils.hpp @@ -7,6 +7,7 @@ namespace hack::utils { + // template auto func_memory(Result (*f)(Args...)) { @@ -17,7 +18,7 @@ namespace hack::utils const auto key = std::make_tuple(args...); const auto cached = cache.find(key); - if(cached == cache.end()) + if (cached == cache.end()) { auto result = f(args...); cache[key] = result; @@ -27,6 +28,8 @@ namespace hack::utils }; } + // обединяет фукнкции в один вызов при одинаковых переменных + // все переменный захватываются по значению template auto func_concat(T t, Args... args) { @@ -46,6 +49,7 @@ namespace hack::utils } } + // вызов unix команд из с++ кода inline std::string unix_cmd(const std::string& cmd) { std::string result; diff --git a/src/meson.build b/src/meson.build index b46b6d1..8a0d984 100755 --- a/src/meson.build +++ b/src/meson.build @@ -1,26 +1,27 @@ inc += include_directories('.') headers = [ - 'hack/concepts/concepts.hpp', - 'hack/container/container.hpp', - 'hack/iterators/associative_ostream_iterator.hpp', - 'hack/iterators/sequence_ostream_iterator.hpp', 'hack/logger/logger.hpp', - 'hack/math/matrix.hpp', - 'hack/math/max.hpp', - 'hack/math/vector.hpp', - 'hack/range/range.hpp', - 'hack/range/range.hpp', - 'hack/security/is_link.hpp', - 'hack/security/is_string.hpp', - 'hack/security/uuid.hpp', - 'hack/security/validate_email.hpp', - 'hack/string/string.hpp', - 'hack/string/string_concat_helper.hpp', - 'hack/string/utf8_len.hpp', - 'hack/utils/func_query.hpp', - 'hack/utils/utils.hpp', - 'hack/view/color.hpp' + 'hack/containers/vector.hpp', + + # 'hack/concepts/concepts.hpp', + # 'hack/iterators/associative_ostream_iterator.hpp', + # 'hack/iterators/sequence_ostream_iterator.hpp', + # 'hack/math/matrix.hpp', + # 'hack/math/max.hpp', + # 'hack/math/vector.hpp', + # 'hack/range/range.hpp', + # 'hack/range/range.hpp', + # 'hack/security/is_link.hpp', + # 'hack/security/is_string.hpp', + # 'hack/security/uuid.hpp', + # 'hack/security/validate_email.hpp', + # 'hack/string/string.hpp', + # 'hack/string/string_concat_helper.hpp', + # 'hack/string/utf8_len.hpp', + # 'hack/utils/func_query.hpp', + # 'hack/utils/utils.hpp', + # 'hack/view/color.hpp' ] sources = []