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 dtl {
36 
37 template <class T, unsigned V>
38 struct version_type
39     : public dtl::integral_constant<unsigned, V>
40 {
41     typedef T type;
42 };
43 
44 namespace impl{
45 
46 template <class T>
47 struct extract_version
48 {
49    typedef typename T::version type;
50 };
51 
52 template <class T>
53 struct has_version
54 {
55    private:
56    struct two {char _[2];};
57    template <class U> static two test(...);
58    template <class U> static char test(const typename U::version*);
59    public:
60    static const bool value = sizeof(test<T>(0)) == 1;
dummyboost::container::dtl::impl::has_version61    void dummy(){}
62 };
63 
64 template <class T, bool = has_version<T>::value>
65 struct version
66 {
67    static const unsigned value = 1;
68 };
69 
70 template <class T>
71 struct version<T, true>
72 {
73    static const unsigned value = extract_version<T>::type::value;
74 };
75 
76 }  //namespace impl
77 
78 template <class T>
79 struct version
80    : public dtl::integral_constant<unsigned, impl::version<T>::value>
81 {};
82 
83 template<class T, unsigned N>
84 struct is_version
85 {
86    static const bool value =
87       is_same< typename version<T>::type, integral_constant<unsigned, N> >::value;
88 };
89 
90 }  //namespace dtl {
91 
92 typedef dtl::integral_constant<unsigned, 0> version_0;
93 typedef dtl::integral_constant<unsigned, 1> version_1;
94 typedef dtl::integral_constant<unsigned, 2> version_2;
95 
96 }  //namespace container {
97 }  //namespace boost{
98 
99 #include <boost/container/detail/config_end.hpp>
100 
101 #endif   //#define BOOST_CONTAINER_DETAIL_VERSION_TYPE_HPP
102