static_holder.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright 2006-2009 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/flyweight for library home page.
  7. */
  8. #ifndef BOOST_FLYWEIGHT_STATIC_HOLDER_HPP
  9. #define BOOST_FLYWEIGHT_STATIC_HOLDER_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/flyweight/static_holder_fwd.hpp>
  15. #include <boost/flyweight/holder_tag.hpp>
  16. #include <boost/mpl/aux_/lambda_support.hpp>
  17. /* Simplest holder storing the T object as a local static variable.
  18. */
  19. namespace boost{
  20. namespace flyweights{
  21. template<typename C>
  22. struct static_holder_class:holder_marker
  23. {
  24. static C& get()
  25. {
  26. static C c;
  27. return c;
  28. }
  29. typedef static_holder_class type;
  30. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,static_holder_class,(C))
  31. };
  32. /* static_holder_class specifier */
  33. struct static_holder:holder_marker
  34. {
  35. template<typename C>
  36. struct apply
  37. {
  38. typedef static_holder_class<C> type;
  39. };
  40. };
  41. } /* namespace flyweights */
  42. } /* namespace boost */
  43. #endif