add switch case as string key

This commit is contained in:
chatlanin 2022-11-07 13:01:31 +03:00
parent 9f47c86bc2
commit 7c79befcb2
4 changed files with 68 additions and 2 deletions

View File

@ -50,6 +50,7 @@ struct counter_test : public hack::utils::counter<int>
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" };
@ -64,10 +65,16 @@ int main(int argc, char *argv[])
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");
@ -75,12 +82,18 @@ int main(int argc, char *argv[])
for(const auto& c : v) hack::log()(c);
}
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 };
@ -105,17 +118,26 @@ int main(int argc, char *argv[])
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 } };
@ -154,6 +176,9 @@ int main(int argc, char *argv[])
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, };
@ -179,12 +204,18 @@ int main(int argc, char *argv[])
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";
@ -193,11 +224,17 @@ int main(int argc, char *argv[])
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"));
@ -205,17 +242,26 @@ int main(int argc, char *argv[])
hack::log::type_trace(t);
}
hack::log()("============================================================");
hack::log()("security::validate_email");
{
// ec: security::validate_email
std::string email = "asdf@asdf.com";
hack::log()(hack::security::validate_email(email));
}
hack::log()("============================================================");
hack::log()("security::generate_uuid");
{
// ec: security::generate_uuid
hack::log()(hack::security::generate_uuid());
}
hack::log()("============================================================");
hack::log()("security::is_string");
{
// ec: security::is_string
std::string s {"test"};
@ -226,8 +272,17 @@ int main(int argc, char *argv[])
hack::log()(hack::security::is_string<decltype ("c")>::value);
}
hack::log()("============================================================");
hack::log()("utils::counter");
{
counter_test a, b, c;
hack::log()(c.id);
}
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;
}
}

View File

@ -1,5 +1,6 @@
executable(
'hack', 'main.cpp',
'hack',
'main.cpp',
dependencies : deps,
cpp_args: args
)

2
run
View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/zsh
TEST="meson test -C build"
RUN="./build/bin/hack"

View File

@ -68,4 +68,14 @@ namespace hack::utils
{
inline static T id = value;
};
// this function can will use
// as switch wiht string
// switch(case_int("key"))
// case case_int("test"): hack::log()("wow!");
// case case_int("no_test"): hack::log()("wow!");
inline constexpr std::uint32_t case_int(const char* str, std::uint32_t hash = 2166136261UL)
{
return *str ? case_int(str + 1, (hash ^ *str) * 16777619ULL) : hash;
}
}