diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e9f4823 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "vendors/enum.hpp"] + path = vendors/enum.hpp + url = https://github.com/BlackMATov/enum.hpp +[submodule "vendors/kari.hpp"] + path = vendors/kari.hpp + url = https://github.com/BlackMATov/kari.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index da1b980..ed72031 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,19 @@ endif() project(meta.hpp) +add_subdirectory(vendors/enum.hpp) +add_subdirectory(vendors/kari.hpp) + add_library(${PROJECT_NAME} INTERFACE) -target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) -target_include_directories(${PROJECT_NAME} INTERFACE headers) + +target_link_libraries(${PROJECT_NAME} + INTERFACE enum.hpp kari.hpp) + +target_compile_features(${PROJECT_NAME} + INTERFACE cxx_std_17) + +target_include_directories(${PROJECT_NAME} + INTERFACE headers) if(BUILD_AS_STANDALONE) option(BUILD_WITH_UNTESTS "Build with unit tests" ON) diff --git a/headers/meta.hpp/meta_fwd.hpp b/headers/meta.hpp/meta_fwd.hpp index 26e9973..8276d6a 100644 --- a/headers/meta.hpp/meta_fwd.hpp +++ b/headers/meta.hpp/meta_fwd.hpp @@ -27,6 +27,11 @@ #include #include +#include +#include + +#include + namespace meta_hpp { class class_info; diff --git a/headers/meta.hpp/meta_registry.hpp b/headers/meta.hpp/meta_registry.hpp index dafe434..0175acf 100644 --- a/headers/meta.hpp/meta_registry.hpp +++ b/headers/meta.hpp/meta_registry.hpp @@ -10,6 +10,7 @@ #include "meta_infos.hpp" #include "meta_registry/class_.hpp" +#include "meta_registry/ctor_.hpp" #include "meta_registry/data_.hpp" #include "meta_registry/enum_.hpp" #include "meta_registry/evalue_.hpp" @@ -164,7 +165,7 @@ namespace meta_hpp inline void registry::add_info_(const std::string& prefix, const class_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(classes_, name, info, &class_info::merge); } @@ -175,43 +176,43 @@ namespace meta_hpp inline void registry::add_info_(const std::string& prefix, const data_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(datas_, name, info, &data_info::merge); } inline void registry::add_info_(const std::string& prefix, const enum_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(enums_, name, info, &enum_info::merge); } inline void registry::add_info_(const std::string& prefix, const evalue_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(evalues_, name, info, &evalue_info::merge); } inline void registry::add_info_(const std::string& prefix, const function_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(functions_, name, info, &function_info::merge); } inline void registry::add_info_(const std::string& prefix, const member_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(members_, name, info, &member_info::merge); } inline void registry::add_info_(const std::string& prefix, const method_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(methods_, name, info, &method_info::merge); } inline void registry::add_info_(const std::string& prefix, const namespace_info& info) { std::string name = prefix.empty() ? info.name() : prefix + "::" + info.name(); - info.visit(curry(add_info_f{}, std::ref(*this), name)); + info.visit(kari_hpp::curry(add_info_f{}, std::ref(*this), name)); detail::merge_with(namespaces_, name, info, &namespace_info::merge); } } diff --git a/headers/meta.hpp/meta_utilities.hpp b/headers/meta.hpp/meta_utilities.hpp index 3ceab77..be54873 100644 --- a/headers/meta.hpp/meta_utilities.hpp +++ b/headers/meta.hpp/meta_utilities.hpp @@ -8,5 +8,5 @@ #include "meta_fwd.hpp" -#include "meta_utilities/curry.hpp" +#include "meta_utilities/arg.hpp" #include "meta_utilities/value.hpp" diff --git a/headers/meta.hpp/meta_utilities/curry.hpp b/headers/meta.hpp/meta_utilities/curry.hpp deleted file mode 100644 index bcf3780..0000000 --- a/headers/meta.hpp/meta_utilities/curry.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * This file is part of the "https://github.com/blackmatov/meta.hpp" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#pragma once - -#include "../meta_fwd.hpp" - -namespace meta_hpp -{ - template < typename F, typename... As > - class curry_t; - - namespace impl - { - template < typename F > - struct is_curried_impl - : std::false_type {}; - - template < typename F, typename... As > - struct is_curried_impl> - : std::true_type {}; - } - - template < typename F > - struct is_curried - : impl::is_curried_impl> {}; - - template < typename F > - inline constexpr bool is_curried_v = is_curried::value; -} - -namespace meta_hpp::detail -{ - template < typename F, typename... Args > - constexpr auto curry_or_apply(F&& f, std::tuple&& args) { - if constexpr ( std::is_invocable_v, Args...> ) { - return std::apply(std::forward(f), std::move(args)); - } else { - return curry_t(std::forward(f), std::move(args)); - } - } -} - -namespace meta_hpp -{ - template < typename F, typename... Args > - class curry_t final { - public: - constexpr curry_t(F f) - : f_(std::move(f)) {} - - constexpr curry_t(F f, std::tuple args) - : f_(std::move(f)) - , args_(std::move(args)) {} - - constexpr auto operator()() && { - return detail::curry_or_apply( - std::move(f_), - std::move(args_)); - } - - template < typename A > - constexpr auto operator()(A&& a) && { - return detail::curry_or_apply( - std::move(f_), - std::tuple_cat( - std::move(args_), - std::make_tuple(std::forward(a)))); - } - - template < typename A, typename... As > - constexpr auto operator()(A&& a, As&&... as) && { - return std::move(*this)(std::forward(a))(std::forward(as)...); - } - - template < typename... As > - constexpr auto operator()(As&&... as) const & { - return std::move(curry_t(*this))(std::forward(as)...); - } - private: - F f_; - std::tuple args_; - }; -} - -namespace meta_hpp -{ - template < typename F > - constexpr auto curry(F&& f) { - if constexpr ( is_curried_v> ) { - return std::forward(f); - } else { - return detail::curry_or_apply(std::forward(f), {}); - } - } - - template < typename F, typename A, typename... As > - constexpr auto curry(F&& f, A&& a, As&&... as) { - return curry(std::forward(f))(std::forward(a), std::forward(as)...); - } -} diff --git a/untests/CMakeLists.txt b/untests/CMakeLists.txt index 524f30f..8e18fd3 100644 --- a/untests/CMakeLists.txt +++ b/untests/CMakeLists.txt @@ -29,9 +29,9 @@ target_compile_options(${PROJECT_NAME} -Werror -Wall -Wextra -Wpedantic> PRIVATE $<$,$>: - -Werror -Weverything -Wno-unknown-warning-option - -Wconversion -Wimplicit-int-float-conversion - -Wno-c++98-compat-pedantic -Wno-ctad-maybe-unsupported -Wno-padded - -Wno-float-equal -Wno-double-promotion -Wno-shadow-field-in-constructor>) + -Werror -Weverything -Wconversion -Wno-unknown-warning-option + -Wno-padded + -Wno-c++98-compat-pedantic + -Wno-shadow-field-in-constructor>) add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/vendors/enum.hpp b/vendors/enum.hpp new file mode 160000 index 0000000..0a549d3 --- /dev/null +++ b/vendors/enum.hpp @@ -0,0 +1 @@ +Subproject commit 0a549d3341e8f6d9efd8e6cea343f2d3ab4e7633 diff --git a/vendors/kari.hpp b/vendors/kari.hpp new file mode 160000 index 0000000..c52226f --- /dev/null +++ b/vendors/kari.hpp @@ -0,0 +1 @@ +Subproject commit c52226f8556a0a439389514143f336fe4979b480