summaryrefslogtreecommitdiffhomepage
path: root/dev/lib
diff options
context:
space:
mode:
Diffstat (limited to 'dev/lib')
-rw-r--r--dev/lib/core/allocator_system.hpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/dev/lib/core/allocator_system.hpp b/dev/lib/core/allocator_system.hpp
index 6b7e5db..1243ed5 100644
--- a/dev/lib/core/allocator_system.hpp
+++ b/dev/lib/core/allocator_system.hpp
@@ -14,33 +14,34 @@
namespace ocl
{
+ template <typename type>
struct new_op final
{
- template <typename type>
inline auto operator()() -> type*
{
return new type;
}
- template <typename type, typename... var_type>
- inline auto operator()(var_type&&... args) -> type*
+ template <typename... var_type>
+ inline auto var_alloc(var_type... args) -> type*
{
- return new type{std::forward(args...)};
+ return new type{args...};
}
};
+ template <typename type>
struct delete_op final
{
- template <typename type>
inline auto operator()(type* t) -> void
{
delete t;
}
};
- template <typename allocator_new, typename allocator_delete>
+ template <typename ret_type, typename allocator_new, typename allocator_delete>
class allocator_system
{
+ allocator_new alloc_;
allocator_delete del_;
public:
@@ -50,26 +51,25 @@ namespace ocl
allocator_system& operator=(const allocator_system&) = delete;
allocator_system(const allocator_system&) = delete;
- template <typename ret_type>
ret_type* claim() noexcept
{
- return allocator_new(sizeof(ret_type));
+ return alloc_();
}
- template <typename ret_type, typename... var_type>
- auto construct(var_type&&... args) -> std::shared_ptr<ret_type>
+ template <typename... var_type>
+ auto construct(var_type... args) -> std::shared_ptr<ret_type>
{
- return std::shared_ptr<ret_type>(allocator_new(ret_type{std::forward<var_type...>(args...)}), del_());
+ return std::shared_ptr<ret_type>(alloc_.template var_alloc<var_type...>(args...), allocator_delete{});
}
- template <typename ret_type>
void unclaim(ret_type* ptr)
{
del_(ptr);
}
};
- using standard_allocator_type = allocator_system<new_op, delete_op>;
+ template <typename type>
+ using standard_allocator_type = allocator_system<type, new_op<type>, delete_op<type>>;
} // namespace ocl
#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP