1 | // Copyright David Abrahams 2003. Use, modification and distribution is
|
---|
2 | // subject to the Boost Software License, Version 1.0. (See accompanying
|
---|
3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
---|
4 | #ifndef MINIMUM_CATEGORY_DWA20031119_HPP
|
---|
5 | # define MINIMUM_CATEGORY_DWA20031119_HPP
|
---|
6 |
|
---|
7 | # include <boost/type_traits/is_convertible.hpp>
|
---|
8 | # include <boost/type_traits/is_same.hpp>
|
---|
9 |
|
---|
10 | # include <boost/mpl/aux_/lambda_support.hpp>
|
---|
11 |
|
---|
12 | namespace boost { namespace detail {
|
---|
13 | //
|
---|
14 | // Returns the minimum category type or error_type
|
---|
15 | // if T1 and T2 are unrelated.
|
---|
16 | //
|
---|
17 | // For compilers not supporting is_convertible this only
|
---|
18 | // works with the new boost return and traversal category
|
---|
19 | // types. The exact boost _types_ are required. No derived types
|
---|
20 | // will work.
|
---|
21 | //
|
---|
22 | //
|
---|
23 | template <bool GreaterEqual, bool LessEqual>
|
---|
24 | struct minimum_category_impl
|
---|
25 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
|
---|
26 | {
|
---|
27 | template <class T1, class T2> struct apply
|
---|
28 | {
|
---|
29 | typedef T2 type;
|
---|
30 | };
|
---|
31 | typedef void type;
|
---|
32 | }
|
---|
33 | # endif
|
---|
34 | ;
|
---|
35 |
|
---|
36 | template <class T1, class T2>
|
---|
37 | struct error_not_related_by_convertibility;
|
---|
38 |
|
---|
39 | template <>
|
---|
40 | struct minimum_category_impl<true,false>
|
---|
41 | {
|
---|
42 | template <class T1, class T2> struct apply
|
---|
43 | {
|
---|
44 | typedef T2 type;
|
---|
45 | };
|
---|
46 | };
|
---|
47 |
|
---|
48 | template <>
|
---|
49 | struct minimum_category_impl<false,true>
|
---|
50 | {
|
---|
51 | template <class T1, class T2> struct apply
|
---|
52 | {
|
---|
53 | typedef T1 type;
|
---|
54 | };
|
---|
55 | };
|
---|
56 |
|
---|
57 | template <>
|
---|
58 | struct minimum_category_impl<true,true>
|
---|
59 | {
|
---|
60 | template <class T1, class T2> struct apply
|
---|
61 | {
|
---|
62 | BOOST_STATIC_ASSERT((is_same<T1,T2>::value));
|
---|
63 | typedef T1 type;
|
---|
64 | };
|
---|
65 | };
|
---|
66 |
|
---|
67 | template <>
|
---|
68 | struct minimum_category_impl<false,false>
|
---|
69 | {
|
---|
70 | template <class T1, class T2> struct apply
|
---|
71 | : error_not_related_by_convertibility<T1,T2>
|
---|
72 | {
|
---|
73 | };
|
---|
74 | };
|
---|
75 |
|
---|
76 | template <class T1 = mpl::_1, class T2 = mpl::_2>
|
---|
77 | struct minimum_category
|
---|
78 | {
|
---|
79 | typedef minimum_category_impl<
|
---|
80 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround
|
---|
81 | is_same<T2,int>::value ||
|
---|
82 | # endif
|
---|
83 | ::boost::is_convertible<T1,T2>::value
|
---|
84 | , ::boost::is_convertible<T2,T1>::value
|
---|
85 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround
|
---|
86 | || is_same<T1,int>::value
|
---|
87 | # endif
|
---|
88 | > outer;
|
---|
89 |
|
---|
90 | typedef typename outer::template apply<T1,T2> inner;
|
---|
91 | typedef typename inner::type type;
|
---|
92 |
|
---|
93 | BOOST_MPL_AUX_LAMBDA_SUPPORT(2,minimum_category,(T1,T2))
|
---|
94 | };
|
---|
95 |
|
---|
96 | template <>
|
---|
97 | struct minimum_category<mpl::_1,mpl::_2>
|
---|
98 | {
|
---|
99 | template <class T1, class T2>
|
---|
100 | struct apply : minimum_category<T1,T2>
|
---|
101 | {};
|
---|
102 |
|
---|
103 | BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2,minimum_category,(mpl::_1,mpl::_2))
|
---|
104 | };
|
---|
105 |
|
---|
106 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround
|
---|
107 | template <>
|
---|
108 | struct minimum_category<int,int>
|
---|
109 | {
|
---|
110 | typedef int type;
|
---|
111 | };
|
---|
112 | # endif
|
---|
113 |
|
---|
114 | }} // namespace boost::detail
|
---|
115 |
|
---|
116 | #endif // MINIMUM_CATEGORY_DWA20031119_HPP
|
---|