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 
15 
16 #ifndef BOOST_CONTAINER_DETAIL_VERSION_TYPE_HPP
17 #define BOOST_CONTAINER_DETAIL_VERSION_TYPE_HPP
18 
19 #ifndef BOOST_CONFIG_HPP
20 #  include <boost/config.hpp>
21 #endif
22 
23 #if defined(BOOST_HAS_PRAGMA_ONCE)
24 #  pragma once
25 #endif
26 
27 #include <boost/container/detail/config_begin.hpp>
28 #include <boost/container/detail/workaround.hpp>
29 
30 #include <boost/container/detail/mpl.hpp>
31 #include <boost/container/detail/type_traits.hpp>
32 
33 namespace boost{
34 namespace container {
35 namespace container_detail {
36 
37 template <class T, unsigned V>
38 struct version_type
39     : public container_detail::integral_constant<unsigned, V>
40 {
41     typedef T type;
42 
43     version_type(const version_type<T, 0>&);
44 };
45 
46 namespace impl{
47 
48 template <class T,
49           bool = container_detail::is_convertible<version_type<T, 0>, typename T::version>::value>
50 struct extract_version
51 {
52    static const unsigned value = 1;
53 };
54 
55 template <class T>
56 struct extract_version<T, true>
57 {
58    static const unsigned value = T::version::value;
59 };
60 
61 template <class T>
62 struct has_version
63 {
64    private:
65    struct two {char _[2];};
66    template <class U> static two test(...);
67    template <class U> static char test(const typename U::version*);
68    public:
69    static const bool value = sizeof(test<T>(0)) == 1;
dummyboost::container::container_detail::impl::has_version70    void dummy(){}
71 };
72 
73 template <class T, bool = has_version<T>::value>
74 struct version
75 {
76    static const unsigned value = 1;
77 };
78 
79 template <class T>
80 struct version<T, true>
81 {
82    static const unsigned value = extract_version<T>::value;
83 };
84 
85 }  //namespace impl
86 
87 template <class T>
88 struct version
89    : public container_detail::integral_constant<unsigned, impl::version<T>::value>
90 {};
91 
92 template<class T, unsigned N>
93 struct is_version
94 {
95    static const bool value =
96       is_same< typename version<T>::type, integral_constant<unsigned, N> >::value;
97 };
98 
99 }  //namespace container_detail {
100 
101 typedef container_detail::integral_constant<unsigned, 0> version_0;
102 typedef container_detail::integral_constant<unsigned, 1> version_1;
103 typedef container_detail::integral_constant<unsigned, 2> version_2;
104 
105 }  //namespace container {
106 }  //namespace boost{
107 
108 #include <boost/container/detail/config_end.hpp>
109 
110 #endif   //#define BOOST_CONTAINER_DETAIL_VERSION_TYPE_HPP
111