thread
Brett 2024-06-20 02:27:23 -04:00
parent 700c9873a8
commit c8dbaef7d3
3 changed files with 35 additions and 27 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) 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_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -296,17 +296,23 @@ void test()
blt::gp::type_system type_system; blt::gp::type_system type_system;
blt::gp::gp_program program(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 add([](float a, float b) { return a + b; });
blt::gp::operation_t<float(float, float)> sub([](float a, float b) { return a - b; }); blt::gp::operation_t sub([](float a, float b) { return a - b; });
blt::gp::operation_t<float(float, float)> mul([](float a, float b) { return a * b; }); blt::gp::operation_t mul([](float a, float b) { return a * b; });
blt::gp::operation_t<float(float, float)> pro_div([](float a, float b) { return b == 0 ? 0.0f : a / b; }); blt::gp::operation_t pro_div([](float a, float b) { return b == 0 ? 0.0f : a / b; });
blt::gp::operation_t<float()> lit([]() {return 0.0f;}); blt::gp::operation_t lit([]() { return 0.0f; });
int main() int main()
{ {
type_system.register_type<float>(); type_system.register_type<float>();
type_system.register_type<bool>(); type_system.register_type<bool>();
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; // constexpr blt::size_t MAX_ALIGNMENT = 8;
// test(); // test();

View File

@ -99,13 +99,6 @@ namespace blt::gp
std::string name_{}; std::string name_{};
}; };
class allowed_types_t
{
public:
private:
};
class type_system class type_system
{ {
public: public:
@ -163,6 +156,8 @@ namespace blt::gp
[[nodiscard]] constexpr inline Return operator()(stack_allocator& allocator) const [[nodiscard]] constexpr inline Return operator()(stack_allocator& allocator) const
{ {
if constexpr (sizeof...(Args) == 0)
return func();
constexpr auto seq = std::make_integer_sequence<blt::u64, sizeof...(Args)>(); constexpr auto seq = std::make_integer_sequence<blt::u64, sizeof...(Args)>();
Return ret = exec_sequence_to_indices(allocator, seq); Return ret = exec_sequence_to_indices(allocator, seq);
allocator.call_destructors<Args...>(); allocator.call_destructors<Args...>();
@ -186,23 +181,30 @@ namespace blt::gp
function_t func; function_t func;
}; };
template<typename Return, typename Class, typename... Args>
class operation_t<Return (Class::*)(Args...) const> : public operation_t<Return(Args...)>
{
public:
using operation_t<Return(Args...)>::operation_t;
};
template<typename Lambda>
operation_t(Lambda) -> operation_t<decltype(&Lambda::operator())>;
template<typename Return, typename... Args> template<typename Return, typename... Args>
operation_t(Return (*)(Args...)) -> operation_t<Return(Args...)>; operation_t(Return (*)(Args...)) -> operation_t<Return(Args...)>;
template<typename Return, typename Class, typename... Args> // templat\e<typename Return, typename Class, typename... Args>
operation_t(Return (Class::*)(Args...) const) -> operation_t<Return(Args...)>; // operation_t<Return(Args...)> make_operator(Return (Class::*)(Args...) const lambda)
// {
template<typename Return, typename Class, typename... Args> // // https://ventspace.wordpress.com/2022/04/11/quick-snippet-c-type-trait-templates-for-lambda-details/
operation_t<Return(Args...)> make_operator(Return (Class::*)(Args...) const lambda) // }
{ //
// https://ventspace.wordpress.com/2022/04/11/quick-snippet-c-type-trait-templates-for-lambda-details/ // template<typename Lambda>
} // operation_t<decltype(&Lambda::operator())> make_operator(Lambda&& lambda)
// {
template<typename Lambda> // return operation_t<decltype(&Lambda::operator())>(std::forward(lambda));
operation_t<decltype(&Lambda::operator())> make_operator(Lambda&& lambda) // }
{
return operation_t<decltype(&Lambda::operator())>(std::forward(lambda));
}
// //
// template<typename Return, typename... Args> // template<typename Return, typename... Args>
// operation(std::function<Return(Args...)>) -> operation<Return(Args...)>; // operation(std::function<Return(Args...)>) -> operation<Return(Args...)>;