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
33namespace boost{
34namespace container {
35namespace container_detail {
36
37template <class T, unsigned V>
38struct 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
46namespace impl{
47
48template <class T,
49 bool = container_detail::is_convertible<version_type<T, 0>, typename T::version>::value>
50struct extract_version
51{
52 static const unsigned value = 1;
53};
54
55template <class T>
56struct extract_version<T, true>
57{
58 static const unsigned value = T::version::value;
59};
60
61template <class T>
62struct 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;
70 void dummy(){}
71};
72
73template <class T, bool = has_version<T>::value>
74struct version
75{
76 static const unsigned value = 1;
77};
78
79template <class T>
80struct version<T, true>
81{
82 static const unsigned value = extract_version<T>::value;
83};
84
85} //namespace impl
86
87template <class T>
88struct version
89 : public container_detail::integral_constant<unsigned, impl::version<T>::value>
90{};
91
92template<class T, unsigned N>
93struct 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
101typedef container_detail::integral_constant<unsigned, 0> version_0;
102typedef container_detail::integral_constant<unsigned, 1> version_1;
103typedef 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