default_value_policy.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright 2006-2024 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_DETAIL_DEFAULT_VALUE_POLICY_HPP
  9. #define BOOST_FLYWEIGHT_DETAIL_DEFAULT_VALUE_POLICY_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/config/workaround.hpp>
  15. #include <boost/flyweight/detail/perfect_fwd.hpp>
  16. #include <boost/flyweight/detail/value_tag.hpp>
  17. /* Default value policy: the key is the same as the value.
  18. */
  19. namespace boost{
  20. namespace flyweights{
  21. namespace detail{
  22. template<typename Value>
  23. struct default_value_policy:value_marker
  24. {
  25. typedef Value key_type;
  26. typedef Value value_type;
  27. struct rep_type
  28. {
  29. /* template ctors */
  30. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)&&\
  31. !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)&&\
  32. BOOST_WORKAROUND(BOOST_GCC,<=40603)
  33. /* GCC bug: the default ctor generated by the variadic template ctor below
  34. * fails to value-initialize x.
  35. */
  36. rep_type():x(){}
  37. #endif
  38. #define BOOST_FLYWEIGHT_PERFECT_FWD_CTR_BODY(args) \
  39. :x(BOOST_FLYWEIGHT_FORWARD(args)){}
  40. BOOST_FLYWEIGHT_PERFECT_FWD(
  41. explicit rep_type,
  42. BOOST_FLYWEIGHT_PERFECT_FWD_CTR_BODY)
  43. #undef BOOST_FLYWEIGHT_PERFECT_FWD_CTR_BODY
  44. rep_type(const rep_type& r):x(r.x){}
  45. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  46. rep_type(rep_type&& r):x(std::move(r.x)){}
  47. #endif
  48. operator const value_type&()const BOOST_NOEXCEPT{return x;}
  49. value_type x;
  50. };
  51. static void key_construct_value(const rep_type&){}
  52. static void copy_construct_value(const rep_type&,const value_type&){}
  53. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  54. static void move_construct_value(const rep_type&,value_type&&){}
  55. #endif
  56. };
  57. } /* namespace flyweights::detail */
  58. } /* namespace flyweights */
  59. } /* namespace boost */
  60. #endif