From 8af186cd8e9ef0badda934989f8a5e0cd1921d0f Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Thu, 29 Feb 2024 11:25:39 -0500 Subject: [PATCH] discard --- CMakeLists.txt | 1 + libs/BLT | 2 +- tests/src/tests.cpp | 80 +++++++++++++++++++++++++++++++++++++-------- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e0e9f0..5f0f936 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ if(!MSVC) add_compile_options(-march=native) endif() +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 17) add_subdirectory(libs/BLT) diff --git a/libs/BLT b/libs/BLT index 89bde7c..ffa20e0 160000 --- a/libs/BLT +++ b/libs/BLT @@ -1 +1 @@ -Subproject commit 89bde7c6e85ab50de988fb3f7b91d2041b41a4cb +Subproject commit ffa20e0e51a8b308458e0b3ca2946af4eef4bae6 diff --git a/tests/src/tests.cpp b/tests/src/tests.cpp index 93d9efe..c5ec985 100644 --- a/tests/src/tests.cpp +++ b/tests/src/tests.cpp @@ -21,10 +21,19 @@ #include #include #include "blt/std/utility.h" +#include "blt/std/hashmap.h" #include +#include #include #include +template +auto run_once() +{ + static auto called = false; + return !std::exchange(called, true); +}; + namespace fb { using arg_t = double; @@ -144,14 +153,12 @@ namespace fb class arg_constraint_container { private: - blt::vector> map; + blt::vector> map; public: - template>>, bool> = true> - constexpr explicit arg_constraint_container(T&& map): map(std::forward(map)) + constexpr explicit arg_constraint_container(const blt::vector>& map): map(map) {} - template>, bool> = true> - constexpr explicit arg_constraint_container(blt::size_t argc, T&& map) + constexpr explicit arg_constraint_container(blt::size_t argc, const blt::vector& map) { for (blt::size_t i = 0; i < argc; i++) this->map.push_back(map); @@ -162,36 +169,83 @@ namespace fb for (const auto& v : maps) this->map.push_back(v); } + + [[nodiscard]] constexpr const blt::vector& getAllowedArguments(blt::size_t arg) const + { + return map[arg]; + } }; template class operator_t { private: + ENUM_TYPE our_type; arg_count_t argc; std::function)> func; arg_constraint_container allowed_inputs; - public: - constexpr operator_t(arg_count_t argc, std::function)> func): argc(argc), func(std::move(func)) + + constexpr operator_t(ENUM_TYPE type, arg_count_t argc, std::function)> func, + arg_constraint_container allowed_inputs): + our_type(type), argc(argc), func(std::move(func)), allowed_inputs(std::move(allowed_inputs)) {} + + public: + static constexpr operator_t make_operator(ENUM_TYPE type, arg_count_t argc, + std::function)> func, + arg_constraint_container allowed_inputs) + { + return operator_t{type, argc, func, allowed_inputs}; + } [[nodiscard]] constexpr arg_count_t argCount() const { return argc; } - [[nodiscard]] constexpr std::function)> function() const + [[nodiscard]] constexpr std::function)>& function() const { return func; } - - + + [[nodiscard]] constexpr const blt::vector& getAllowedArguments(blt::size_t arg) const + { return allowed_inputs.getAllowedArguments(arg); } + + [[nodiscard]] constexpr ENUM_TYPE type() const + { return our_type; } }; - template + template + struct operator_container_constructor_t; + + template + struct operator_container_t + { + friend operator_container_constructor_t; + private: + constexpr operator_container_t(std::initializer_list>> list) + { + for (const auto& v : list) + { + operators[static_cast(v.first)] = v.second; + max_argc = std::max(v.second.argCount(), max_argc); + } + } + + public: + arg_count_t max_argc; + std::array, ENUM_MAX> operators; + + [[nodiscard]] constexpr arg_count_t getMaxArgc() const + { + return max_argc; + } + }; + + template typename ALLOC> class node_tree { private: - static ALLOC allocator; + static ALLOC allocator; struct node { - std::array children; + std::array children; NODE_CONTAINER caller; }; public: