version_type.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // This code comes from N1953 document by Howard E. Hinnant
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #ifndef BOOST_CONTAINER_DETAIL_VERSION_TYPE_HPP
  15. #define BOOST_CONTAINER_DETAIL_VERSION_TYPE_HPP
  16. #ifndef BOOST_CONFIG_HPP
  17. # include <boost/config.hpp>
  18. #endif
  19. #if defined(BOOST_HAS_PRAGMA_ONCE)
  20. # pragma once
  21. #endif
  22. #include <boost/container/detail/config_begin.hpp>
  23. #include <boost/container/detail/workaround.hpp>
  24. #include <boost/container/detail/mpl.hpp>
  25. #include <boost/container/detail/type_traits.hpp>
  26. namespace boost{
  27. namespace container {
  28. namespace dtl {
  29. template <class T, unsigned V>
  30. struct version_type
  31. : public dtl::integral_constant<unsigned, V>
  32. {
  33. typedef T type;
  34. };
  35. namespace impl{
  36. template <class T>
  37. struct extract_version
  38. {
  39. typedef typename T::version type;
  40. };
  41. template <class T>
  42. struct has_version
  43. {
  44. private:
  45. struct two {char _[2];};
  46. template <class U> static two test(...);
  47. template <class U> static char test(const typename U::version*);
  48. public:
  49. static const bool value = sizeof(test<T>(0)) == 1;
  50. void dummy(){}
  51. };
  52. template <class T, bool = has_version<T>::value>
  53. struct version
  54. {
  55. static const unsigned value = 1;
  56. };
  57. template <class T>
  58. struct version<T, true>
  59. {
  60. static const unsigned value = extract_version<T>::type::value;
  61. };
  62. } //namespace impl
  63. template <class T>
  64. struct version
  65. : public dtl::integral_constant<unsigned, impl::version<T>::value>
  66. {};
  67. template<class T, unsigned N>
  68. struct is_version
  69. {
  70. static const bool value =
  71. is_same< typename version<T>::type, integral_constant<unsigned, N> >::value;
  72. };
  73. } //namespace dtl {
  74. typedef dtl::integral_constant<unsigned, 0> version_0;
  75. typedef dtl::integral_constant<unsigned, 1> version_1;
  76. typedef dtl::integral_constant<unsigned, 2> version_2;
  77. } //namespace container {
  78. } //namespace boost{
  79. #include <boost/container/detail/config_end.hpp>
  80. #endif //#define BOOST_CONTAINER_DETAIL_VERSION_TYPE_HPP