diff --git a/examples/src/curry.cpp b/examples/src/curry.cpp new file mode 100644 index 0000000..1533cb9 --- /dev/null +++ b/examples/src/curry.cpp @@ -0,0 +1,9 @@ +#include +#include + +auto main() -> int { + constexpr auto f = utempl::Curry([](auto... args){ + return (0 + ... + args); + }); + std::cout << f(1)(2)(3) << std::endl; // Call on cast to return type +}; diff --git a/examples/src/menu.cpp b/examples/src/menu.cpp new file mode 100644 index 0000000..0fa6edb --- /dev/null +++ b/examples/src/menu.cpp @@ -0,0 +1,13 @@ +#include +#include + +auto main() -> int { + utempl::menu::Menu{} + .With<{"This is 0"}>([]{ + std::cout << "You entered 0" << std::endl; + }) + .With<{"Some Long", "S"}>([]{ + std::cout << "It aligns the output to the longest element" << std::endl; + }) + .Run<"[{0}]{2} - |{1}|\n">(); +}; diff --git a/examples/src/meta.cpp b/examples/src/meta.cpp new file mode 100644 index 0000000..3f73537 --- /dev/null +++ b/examples/src/meta.cpp @@ -0,0 +1,9 @@ +#include +#include +#include + +auto main() -> int { + constexpr std::array types = {utempl::kTypeId, utempl::kTypeId}; + static_assert(std::is_same_v::Type, int>); + static_assert(std::is_same_v::Type, void>); +}; diff --git a/examples/src/overloaded.cpp b/examples/src/overloaded.cpp new file mode 100644 index 0000000..28a1345 --- /dev/null +++ b/examples/src/overloaded.cpp @@ -0,0 +1,13 @@ +#include +#include + + +auto main() -> int { + utempl::Overloaded( + [](auto&& arg){ + }, + [](int arg) { + std::cout << arg << std::endl; + } + )(42); +}; diff --git a/include/utempl/loopholes/core.hpp b/include/utempl/loopholes/core.hpp new file mode 100644 index 0000000..953a87c --- /dev/null +++ b/include/utempl/loopholes/core.hpp @@ -0,0 +1,20 @@ +#pragma once + +namespace utempl::loopholes { + +template +struct Getter { + friend constexpr auto Magic(Getter); +}; +template +struct Injector { + friend constexpr auto Magic(Getter) {return Value;}; +}; + + +template +concept Injected = requires{Magic(Getter{});}; + + + +} // namespace utempl::loopholes diff --git a/include/utempl/loopholes/counter.hpp b/include/utempl/loopholes/counter.hpp new file mode 100644 index 0000000..f4d773d --- /dev/null +++ b/include/utempl/loopholes/counter.hpp @@ -0,0 +1,35 @@ +#pragma once +#include +#include + +namespace utempl::loopholes { + +namespace impl { + +template +struct TagWithTalue {}; + +template {}>{}> +constexpr auto Counter(...) { + return I; +}; + +template +consteval auto Counter(std::size_t arg) requires Injected{}, Ts...> { + return Counter(arg); +}; +} // namespace impl; + +// For incerement counter need a unique Ts... +template < + typename Tag, + typename... Ts, + auto R = impl::Counter<0, Tag, Ts...>(std::size_t{}) +> +consteval auto Counter(auto...) { + return R; +}; + + + +} // namespace utempl::loopholes diff --git a/include/utempl/meta_info.hpp b/include/utempl/meta_info.hpp new file mode 100644 index 0000000..44ef97a --- /dev/null +++ b/include/utempl/meta_info.hpp @@ -0,0 +1,38 @@ +#pragma once +#include +#include +#include + +namespace utempl { + +namespace impl { + +struct Types {}; +} // namespace impl + + +template +struct MetaInfoKey { + +}; + + +template +struct MetaInfo { + static constexpr std::size_t kTypeId = loopholes::Counter(); + using Type = T; +private: + static constexpr auto _ = loopholes::Injector{}, TypeList{}>{}; + +}; + +template +inline constexpr std::size_t kTypeId = MetaInfo::kTypeId; + +template +using GetMetaInfo = MetaInfo{}>{}))::Type>; + +template +using GetType = GetMetaInfo::Type; + +} // namespace utempl