exception_disposer.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
  13. #define BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #if defined(BOOST_HAS_PRAGMA_ONCE)
  18. # pragma once
  19. #endif
  20. #include <boost/intrusive/detail/workaround.hpp>
  21. namespace boost {
  22. namespace intrusive {
  23. namespace detail {
  24. template<class Container, class Disposer>
  25. class exception_disposer
  26. {
  27. Container *cont_;
  28. Disposer &disp_;
  29. exception_disposer(const exception_disposer&);
  30. exception_disposer &operator=(const exception_disposer&);
  31. public:
  32. exception_disposer(Container &cont, Disposer &disp)
  33. : cont_(&cont), disp_(disp)
  34. {}
  35. inline void release()
  36. { cont_ = 0; }
  37. ~exception_disposer()
  38. {
  39. if(cont_){
  40. cont_->clear_and_dispose(disp_);
  41. }
  42. }
  43. };
  44. } //namespace detail{
  45. } //namespace intrusive{
  46. } //namespace boost{
  47. #endif //BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP