default_value_policy.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright 2006-2019 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/detail/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{return x;}
  49. value_type x;
  50. };
  51. static void construct_value(const rep_type&){}
  52. static void copy_value(const rep_type&){}
  53. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  54. static void move_value(const rep_type&){}
  55. #endif
  56. };
  57. } /* namespace flyweights::detail */
  58. } /* namespace flyweights */
  59. } /* namespace boost */
  60. #endif