diff --git a/examples/UniquePtrWithPool/Main.cpp b/examples/UniquePtrWithPool/Main.cpp index 1ac0d04a..c3172ff9 100644 --- a/examples/UniquePtrWithPool/Main.cpp +++ b/examples/UniquePtrWithPool/Main.cpp @@ -14,31 +14,15 @@ struct S double b; }; -// Custom deleter that returns S* to the pool -// This class is defined to be able to log the release of objects back to the pool. -// Normally, you would use the predefined etl::ipool::destroyer -struct Deleter -{ - Deleter(etl::pool& p) - : pool(&p) {} - - void operator()(S* ptr) const - { - if (ptr) - { - std::cout << "Releasing S(" << ptr->a << ", " << ptr->b << ") back to pool." << std::endl; - pool->destroy(ptr); - } - } - - etl::pool* pool; -}; - int main() { etl::pool pool; - Deleter pool_deleter(pool); - using Unique = etl::unique_ptr; + auto pool_deleter = [&pool](auto ptr) + { + std::cout << "Releasing S(" << ptr->a << ", " << ptr->b << ") back to pool." << std::endl; + pool.destroy(ptr); + }; + using Unique = etl::unique_ptr; Unique us1(pool.create(1, 2), pool_deleter); std::cout << "Created S(" << us1->a << ", " << us1->b << ") from pool." << std::endl; diff --git a/include/etl/ipool.h b/include/etl/ipool.h index 2fe066bb..43e5f5bd 100644 --- a/include/etl/ipool.h +++ b/include/etl/ipool.h @@ -271,58 +271,6 @@ namespace etl const_iterator(value_type p, pool_type* pool_) : ipool_iterator(p, pool_) {} }; - //*************************************************************************** - /// A releaser is a functor that releases an object back to the pool. - //*************************************************************************** - class releaser - { - public: - - releaser(etl::ipool& p) - : pool(&p) - { - } - - template - void operator()(const T* const p_object) const - { - if (p_object) - { - pool->release(p_object); - } - } - - private: - - etl::ipool* pool; - }; - - //*************************************************************************** - /// A destroyer is a functor that destroys an object and releases it back to the pool. - //*************************************************************************** - class destroyer - { - public: - - destroyer(etl::ipool& p) - : pool(&p) - { - } - - template - void operator()(const T* const p_object) const - { - if (p_object) - { - pool->destroy(p_object); - } - } - - private: - - etl::ipool* pool; - }; - //*************************************************************************** iterator begin() { diff --git a/test/test_pool.cpp b/test/test_pool.cpp index 5f6d76ab..df9b088c 100644 --- a/test/test_pool.cpp +++ b/test/test_pool.cpp @@ -774,9 +774,8 @@ namespace TEST(test_releaser_functor_with_unique_ptr) { etl::pool pool; - using Deleter = etl::ipool::releaser; - Deleter pool_deleter(pool); - using Unique = etl::unique_ptr; + auto pool_deleter = [&pool](S* ptr) { pool.release(ptr); }; + using Unique = etl::unique_ptr; S::instance_count = 0; @@ -823,9 +822,8 @@ namespace TEST(test_destroyer_functor_with_unique_ptr) { etl::pool pool; - using Deleter = etl::ipool::destroyer; - Deleter pool_deleter(pool); - using Unique = etl::unique_ptr; + auto pool_deleter = [&pool](S* ptr) { pool.destroy(ptr); }; + using Unique = etl::unique_ptr; S::instance_count = 0;