From 8bfe09e7db18c706b8651899783b69c046e9be32 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Thu, 6 Jun 2024 16:52:46 -0400 Subject: [PATCH] silly --- CMakeLists.txt | 2 +- examples/main.cpp | 7 +++++-- include/blt/gp/program.h | 30 ++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aca07eb..283b44d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.18) +project(blt-gp VERSION 0.0.19) 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 0664472..097733c 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -368,9 +368,12 @@ int main() alloc.push(120); alloc.push(true); - blt::gp::operation silly_op(nyah); + blt::gp::operation silly_op(nyah); + blt::gp::operation silly_op_2([](float f, float g) { + return f + g; + }); - std::cout << silly_op(alloc) << std::endl; + std::cout << silly_op_2(alloc) << std::endl; std::cout << "Is empty? " << alloc.empty() << std::endl; diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index c3521ee..218b079 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -87,20 +87,21 @@ namespace blt::gp std::vector types; }; + template + class operation; + template - class operation + class operation { public: using function_t = std::function; - operation(const operation& copy) = default; + constexpr operation(const operation& copy) = default; - operation(operation&& move) = default; + constexpr operation(operation&& move) = default; - explicit operation(const function_t& functor): func(functor) - {} - - explicit operation(function_t&& functor): func(std::move(functor)) + template + constexpr explicit operation(const Functor& functor): func(functor) {} template @@ -113,15 +114,15 @@ namespace blt::gp } template - inline Return sequence_to_indices(stack_allocator& allocator, std::integer_sequence) const + inline constexpr Return sequence_to_indices(stack_allocator& allocator, std::integer_sequence) const { // expands Args and indices, providing each argument with its index calculating the current argument byte offset return func(allocator.from(getByteOffset())...); } - [[nodiscard]] inline Return operator()(stack_allocator& allocator) const + [[nodiscard]] constexpr inline Return operator()(stack_allocator& allocator) const { - auto seq = std::make_integer_sequence(); + constexpr auto seq = std::make_integer_sequence(); Return ret = sequence_to_indices(allocator, seq); allocator.pop_bytes((stack_allocator::aligned_size() + ...)); return ret; @@ -143,6 +144,15 @@ namespace blt::gp function_t func; }; + template + operation(Return (*)(Args...)) -> operation; +// +// template +// operation(std::function) -> operation; +// +// template +// operation(std::function) -> operation; + }