add new examples

This commit is contained in:
chatlanin 2023-08-14 11:02:39 +03:00
parent 0339df9279
commit 1242044571
25 changed files with 442 additions and 446 deletions

31
bin/concepts/main.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <set>
#include "hack/logger/logger.hpp"
#include "hack/concepts/concepts.hpp"
template<hack::concepts::is_map T>
void test_map(const T& m)
{
hack::log()("is map", m);
}
template<hack::concepts::is_associative_container T>
void test_associative(const T& m)
{
hack::log()("is associative", m);
}
auto main(int argc, char *argv[]) -> int
{
std::map<std::string, int> 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<int> v { 1, 2, 3 };
// test_associative(v); error !!!
}

40
bin/containers/main.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <set>
#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<std::string> 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<std::string> v { "aa", "bb", "cc" };
auto r = hack::containers::utils::count(v, "aa", "bb");
hack::log()(r);
}
{// ex: containers::set
std::set<int> s;
hack::containers::set::multiset(s, 1, 2, 3);
hack::warn()("TODO: реализовать в log вывод set контейнера!");
}
}

25
bin/iterators/main.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <set>
#include "hack/logger/logger.hpp"
#include "hack/iterators/associative_ostream_iterator.hpp"
#include "hack/concepts/concepts.hpp"
template<hack::concepts::is_map T>
static void print_t(const T& data)
{
std::cout << "{";
std::copy(data.cbegin(), data.cend(), hack::iterators::associative_ostream_iterator<typename T::value_type>(data.size(), std::cout));
std::cout << "}";
}
auto main(int argc, char *argv[]) -> int
{
std::map<std::string, int> m { { "a", 1 }, { "b", 2 } };
for (auto& [key, value] : m)
hack::log()(key, value);
print_t(m);
}

14
bin/logger/main.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <set>
#include "hack/logger/logger.hpp"
auto main(int argc, char *argv[]) -> int
{
std::set<int> s { 1, 2, 3 };
hack::log()(s);
std::vector<int> v { 1, 2, 3 };
hack::log()(v, s);
}

12
bin/macros/main.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <set>
#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);
}

View File

@ -1,351 +0,0 @@
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string_view>
#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<int>::id } { }
int id;
};
struct counter_test_2
{
counter_test_2() : id { ++hack::utils::counter<int>::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<std::string> 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<int> 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<std::string> vs { "asdf", "qwer", "zxcv" };
hack::log()("vector", vs, 1, 2, 'a');
std::list<std::string> ls { "asdf", "qwer", "zxcv" };
hack::log()(vs, ls);
std::map<int, std::string> m { { 1, "asdf" }, { 2, "qwer" }, { 3, "zxcv" } };
hack::log()(vs, ls, m);
std::tuple<int, std::string, bool> tp { 1, "tuple test", false };
hack::log()(tp);
}
hack::log()("============================================================");
hack::log()("container::matches");
{// ex: container::matches
std::vector<int> 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<int> 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<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);
}
hack::log()("============================================================");
hack::log()("math::vector");
{// ex: math::vector
hack::vector<int, int, int> v3_1 { 8, 4, 9, };
hack::vector<int, int, int> 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<int, int> v2_1 { 11, 22 };
hack::log()("length 2", v2_1.length());
hack::vector<int, int, int> lerp_1 { 1, 2, 3 };
hack::vector<int, int, int> 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<decltype ("test_string")>::value);
hack::log()(hack::security::is_string<decltype (s)>::value);
hack::log()(hack::security::is_string<decltype (123)>::value);
hack::log()(hack::security::is_string<decltype ('c')>::value);
hack::log()(hack::security::is_string<decltype ("c")>::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);
}
}

16
bin/memory/main.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <array>
#include "hack/logger/logger.hpp"
#include "hack/memory/make_ptr.hpp"
auto main(int argc, char *argv[]) -> int
{
auto a = hack::memory::make_unique<int>(5);
hack::log()(*a);
auto arr = hack::memory::make_unique<int[]>(5);
arr[0] = 1;
hack::log()(arr[0]);
}

View File

@ -1,6 +1,6 @@
executable(
'hack',
'main.cpp',
'utils/main.cpp',
dependencies : deps,
cpp_args: args,
include_directories : inc

25
bin/security/main.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <array>
#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<decltype (url)>::value);
std::string email = "asdf@asdf.com";
hack::log()(hack::security::validate_email(email));;
}

42
bin/string/main.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <array>
#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);
}
}

88
bin/utils/main.cpp Normal file
View File

@ -0,0 +1,88 @@
#include <array>
#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<int>::id } { }
int id;
};
struct counter_test_2
{
counter_test_2() : id { ++hack::utils::counter<int>::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);
}
}

View File

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

View File

@ -4,28 +4,40 @@
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <concepts>
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>>;
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>>;
template<typename T>
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>;
concept is_set = std::same_as<T, std::set<typename T::key_type, typename T::key_compare, typename T::allocator_type>>;
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>>;
concept is_string = std::is_convertible_v<T, std::string_view>;
template<typename T, std::size_t N = 0>
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::is_array_v<T> && N > 0);
template<typename T>
concept is_associative_container = is_map<T> || is_tuple<T> || is_set<T>;
template<typename T>
concept not_defined = !std::enable_if_t<!(std::integral<T> ||
is_sequence_container<T> ||
is_map<T> ||
is_tuple<T> ||
is_set<T> ||
std::is_array<T>() ||
is_string<T>), bool>() == true;
}

View File

@ -1,50 +0,0 @@
#pragma once
#include <algorithm>
#include <vector>
namespace hack::container
{
template<typename Range, typename... Args>
void vector_multiset(Range& r, Args... args)
{
constexpr std::size_t t = sizeof... (args);
r.reserve(t);
(r.emplace_back(std::forward<Args>(args)), ...);
}
template<typename Range, typename... Args>
void set_multiset(Range& r, Args... args)
{
(r.insert(args), ...);
}
template<typename Range, typename... Args>
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<typename T>
void vector_remove_at(std::vector<T>& v, std::size_t idx)
{
if (idx < v.size())
{
v[idx] = std::move(v.back());
v.pop_back();
}
}
template<typename T>
void vector_remove_at(std::vector<T>& v, typename std::vector<T>::iterator it)
{
if (it != v.end())
{
*it = std::move(v.back());
v.pop_back();
}
}
// -----------------------------------------------------
}

View File

@ -0,0 +1,5 @@
#pragma once
#include "vector.hpp"
#include "utils.hpp"
#include "set.hpp"

11
src/hack/containers/set.hpp Executable file
View File

@ -0,0 +1,11 @@
#pragma once
namespace hack::containers::set
{
// множественная вставка элементов
template<typename Range, typename... Args>
void multiset(Range& r, Args... args)
{
(r.insert(args), ...);
}
}

14
src/hack/containers/utils.hpp Executable file
View File

@ -0,0 +1,14 @@
#pragma once
#include <algorithm>
#include <vector>
namespace hack::containers::utils
{
// подсчитывает кол-во присутствующих элементов в диапозоне
template<typename Range, typename... Args>
int count(Range r, Args... args)
{
return (std::count(std::cbegin(r), std::cend(r), args) + ...);
}
}

38
src/hack/containers/vector.hpp Executable file
View File

@ -0,0 +1,38 @@
#pragma once
#include <algorithm>
#include <vector>
namespace hack::containers::vector
{
// множественная вставка элементов
template<typename Range, typename... Args>
void multiset(Range& r, Args... args)
{
constexpr std::size_t t = sizeof... (args);
r.reserve(t);
(r.emplace_back(std::forward<Args>(args)), ...);
}
// удаление элемента вектора по его индексу, если не важна сортировка
template<typename T>
void remove_at(std::vector<T>& v, std::size_t idx)
{
if (idx < v.size())
{
v[idx] = std::move(v.back());
v.pop_back();
}
}
// удаление элемента вектора по его итератору, если не важна сортировка
template<typename T>
void remove_at(std::vector<T>& v, typename std::vector<T>::iterator it)
{
if (it != v.end())
{
*it = std::move(v.back());
v.pop_back();
}
}
}

View File

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

View File

@ -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<typename T, typename... Args>
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<concepts::is_set T>
static void print_t(const T& data)
{
std::cout << "{ ";
std::copy(data.cbegin(), data.cend(), iterators::sequence_ostream_iterator<typename T::value_type>(data.size(), std::cout));
std::cout << " }" << (count != 0 ? devider : "");
}
template<concepts::is_map T>
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<demention>(r));
std::cout << " }" << (index != 0 ? ", " : "");

View File

@ -1,6 +1,7 @@
#pragma once
#include <type_traits>
#include <algorithm>
namespace hack
{
@ -10,6 +11,6 @@ namespace hack
template<typename T, typename U, typename RT = std::common_type_t<T, U>>
inline RT max(T a, U b)
{
return a > b ? a : b;
return std::max(a, b);
}
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <concepts>
#include <memory>
#include "hack/concepts/concepts.hpp"
namespace hack::memory
{
// обсуждение тут: https://stackoverflow.com/questions/10149840/c-arrays-and-make-unique
template <typename T, typename ...Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type make_unique(Args &&...args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <typename T>
typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type make_unique(std::size_t n)
{
using RT = typename std::remove_extent<T>::type;
return std::unique_ptr<T>(new RT[n]);
}
}

View File

@ -1,13 +0,0 @@
#pragma once
namespace hack::range
{
// являются ли числа максимум и минимум последовательности
template<typename T, typename... Args>
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) && ...);
}
}

View File

@ -7,6 +7,7 @@
namespace hack::utils
{
//
template<typename Result, typename... Args>
auto func_memory(Result (*f)(Args...))
{
@ -27,6 +28,8 @@ namespace hack::utils
};
}
// обединяет фукнкции в один вызов при одинаковых переменных
// все переменный захватываются по значению
template<typename T, typename... Args>
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;

View File

@ -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 = []