silly
parent
7731ec9ebc
commit
8bfe09e7db
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
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_ADDRSAN "Enable the address sanitizer" OFF)
|
||||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||||
|
|
|
@ -368,9 +368,12 @@ int main()
|
||||||
alloc.push(120);
|
alloc.push(120);
|
||||||
alloc.push(true);
|
alloc.push(true);
|
||||||
|
|
||||||
blt::gp::operation<float, float, int, bool> silly_op(nyah);
|
blt::gp::operation<float(float, int, bool)> silly_op(nyah);
|
||||||
|
blt::gp::operation<float(float,float)> 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;
|
std::cout << "Is empty? " << alloc.empty() << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -87,20 +87,21 @@ namespace blt::gp
|
||||||
std::vector<type> types;
|
std::vector<type> types;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Signature>
|
||||||
|
class operation;
|
||||||
|
|
||||||
template<typename Return, typename... Args>
|
template<typename Return, typename... Args>
|
||||||
class operation
|
class operation<Return(Args...)>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using function_t = std::function<Return(Args...)>;
|
using function_t = std::function<Return(Args...)>;
|
||||||
|
|
||||||
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)
|
template<typename Functor>
|
||||||
{}
|
constexpr explicit operation(const Functor& functor): func(functor)
|
||||||
|
|
||||||
explicit operation(function_t&& functor): func(std::move(functor))
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<blt::u64 index>
|
template<blt::u64 index>
|
||||||
|
@ -113,15 +114,15 @@ namespace blt::gp
|
||||||
}
|
}
|
||||||
|
|
||||||
template<blt::u64... indices>
|
template<blt::u64... indices>
|
||||||
inline Return sequence_to_indices(stack_allocator& allocator, std::integer_sequence<blt::u64, indices...>) const
|
inline constexpr Return sequence_to_indices(stack_allocator& allocator, std::integer_sequence<blt::u64, indices...>) const
|
||||||
{
|
{
|
||||||
// expands Args and indices, providing each argument with its index calculating the current argument byte offset
|
// expands Args and indices, providing each argument with its index calculating the current argument byte offset
|
||||||
return func(allocator.from<Args>(getByteOffset<indices>())...);
|
return func(allocator.from<Args>(getByteOffset<indices>())...);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline Return operator()(stack_allocator& allocator) const
|
[[nodiscard]] constexpr inline Return operator()(stack_allocator& allocator) const
|
||||||
{
|
{
|
||||||
auto seq = std::make_integer_sequence<blt::u64, sizeof...(Args)>();
|
constexpr auto seq = std::make_integer_sequence<blt::u64, sizeof...(Args)>();
|
||||||
Return ret = sequence_to_indices(allocator, seq);
|
Return ret = sequence_to_indices(allocator, seq);
|
||||||
allocator.pop_bytes((stack_allocator::aligned_size<Args>() + ...));
|
allocator.pop_bytes((stack_allocator::aligned_size<Args>() + ...));
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -143,6 +144,15 @@ namespace blt::gp
|
||||||
function_t func;
|
function_t func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Return, typename... Args>
|
||||||
|
operation(Return (*)(Args...)) -> operation<Return(Args...)>;
|
||||||
|
//
|
||||||
|
// template<typename Sig>
|
||||||
|
// operation(std::function<Sig>) -> operation<Sig>;
|
||||||
|
//
|
||||||
|
// template<typename Return, typename... Args>
|
||||||
|
// operation(std::function<Return(Args...)>) -> operation<Return(Args...)>;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue