From c8dbaef7d35fd8065c155fdecb49e50bc63f4c07 Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 20 Jun 2024 02:27:23 -0400 Subject: [PATCH] goodbye --- CMakeLists.txt | 2 +- examples/main.cpp | 16 ++++++++++----- include/blt/gp/program.h | 44 +++++++++++++++++++++------------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c769391..1ac47d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.23) +project(blt-gp VERSION 0.0.24) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/examples/main.cpp b/examples/main.cpp index 1a8f61f..858aa16 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -296,17 +296,23 @@ void test() blt::gp::type_system type_system; blt::gp::gp_program program(type_system); -blt::gp::operation_t add = blt::gp::make_operator([](float a, float b) { return a + b; }); -blt::gp::operation_t sub([](float a, float b) { return a - b; }); -blt::gp::operation_t mul([](float a, float b) { return a * b; }); -blt::gp::operation_t pro_div([](float a, float b) { return b == 0 ? 0.0f : a / b; }); -blt::gp::operation_t lit([]() {return 0.0f;}); +blt::gp::operation_t add([](float a, float b) { return a + b; }); +blt::gp::operation_t sub([](float a, float b) { return a - b; }); +blt::gp::operation_t mul([](float a, float b) { return a * b; }); +blt::gp::operation_t pro_div([](float a, float b) { return b == 0 ? 0.0f : a / b; }); +blt::gp::operation_t lit([]() { return 0.0f; }); int main() { type_system.register_type(); type_system.register_type(); + + program.add_operator(add); + program.add_operator(sub); + program.add_operator(mul); + program.add_operator(pro_div); + program.add_operator(lit); // constexpr blt::size_t MAX_ALIGNMENT = 8; // test(); diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index b549755..87a4722 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -99,13 +99,6 @@ namespace blt::gp std::string name_{}; }; - class allowed_types_t - { - public: - - private: - }; - class type_system { public: @@ -163,6 +156,8 @@ namespace blt::gp [[nodiscard]] constexpr inline Return operator()(stack_allocator& allocator) const { + if constexpr (sizeof...(Args) == 0) + return func(); constexpr auto seq = std::make_integer_sequence(); Return ret = exec_sequence_to_indices(allocator, seq); allocator.call_destructors(); @@ -186,23 +181,30 @@ namespace blt::gp function_t func; }; + template + class operation_t : public operation_t + { + public: + using operation_t::operation_t; + }; + + template + operation_t(Lambda) -> operation_t; + template operation_t(Return (*)(Args...)) -> operation_t; - template - operation_t(Return (Class::*)(Args...) const) -> operation_t; - - template - operation_t make_operator(Return (Class::*)(Args...) const lambda) - { - // https://ventspace.wordpress.com/2022/04/11/quick-snippet-c-type-trait-templates-for-lambda-details/ - } - - template - operation_t make_operator(Lambda&& lambda) - { - return operation_t(std::forward(lambda)); - } +// templat\e +// operation_t make_operator(Return (Class::*)(Args...) const lambda) +// { +// // https://ventspace.wordpress.com/2022/04/11/quick-snippet-c-type-trait-templates-for-lambda-details/ +// } +// +// template +// operation_t make_operator(Lambda&& lambda) +// { +// return operation_t(std::forward(lambda)); +// } // // template // operation(std::function) -> operation;