1 | /*=============================================================================
|
---|
2 | Copyright (c) 1999-2003 Jaakko Järvi
|
---|
3 | Copyright (c) 2001-2003 Joel de Guzman
|
---|
4 |
|
---|
5 | Use, modification and distribution is subject to the Boost Software
|
---|
6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
7 | http://www.boost.org/LICENSE_1_0.txt)
|
---|
8 | ==============================================================================*/
|
---|
9 | #if !defined(FUSION_SEQUENCE_DETAIL_AS_TUPLE_ELEMENT_HPP)
|
---|
10 | #define FUSION_SEQUENCE_DETAIL_AS_TUPLE_ELEMENT_HPP
|
---|
11 |
|
---|
12 | #include <boost/ref.hpp>
|
---|
13 |
|
---|
14 | #if defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
15 | # include <boost/mpl/eval_if.hpp>
|
---|
16 | # include <boost/mpl/identity.hpp>
|
---|
17 | # include <boost/type_traits/is_array.hpp>
|
---|
18 | # include <boost/type_traits/is_convertible.hpp>
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | namespace boost { namespace fusion { namespace detail
|
---|
22 | {
|
---|
23 | #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
24 |
|
---|
25 | template <typename T>
|
---|
26 | struct as_tuple_element
|
---|
27 | {
|
---|
28 | typedef T type;
|
---|
29 | };
|
---|
30 |
|
---|
31 | template <typename T>
|
---|
32 | struct as_tuple_element<reference_wrapper<T> >
|
---|
33 | {
|
---|
34 | typedef T& type;
|
---|
35 | };
|
---|
36 |
|
---|
37 | #if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
---|
38 |
|
---|
39 | template <typename T>
|
---|
40 | struct as_tuple_element<reference_wrapper<T> const>
|
---|
41 | {
|
---|
42 | typedef T& type;
|
---|
43 | };
|
---|
44 |
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | template <typename T, int N>
|
---|
48 | struct as_tuple_element<T[N]>
|
---|
49 | {
|
---|
50 | typedef const T(&type)[N];
|
---|
51 | };
|
---|
52 |
|
---|
53 | template <typename T, int N>
|
---|
54 | struct as_tuple_element<volatile T[N]>
|
---|
55 | {
|
---|
56 | typedef const volatile T(&type)[N];
|
---|
57 | };
|
---|
58 |
|
---|
59 | template <typename T, int N>
|
---|
60 | struct as_tuple_element<const volatile T[N]>
|
---|
61 | {
|
---|
62 | typedef const volatile T(&type)[N];
|
---|
63 | };
|
---|
64 |
|
---|
65 | #else
|
---|
66 |
|
---|
67 | // The Non-PTS version cannot accept arrays since there is no way to
|
---|
68 | // get the element type of an array T[N]. However, we shall provide
|
---|
69 | // the most common case where the array is a char[N] or wchar_t[N].
|
---|
70 | // Doing so will allow literal string argument types.
|
---|
71 |
|
---|
72 | template <typename T>
|
---|
73 | struct maybe_string
|
---|
74 | {
|
---|
75 | typedef typename
|
---|
76 | mpl::eval_if<
|
---|
77 | is_array<T>
|
---|
78 | , mpl::eval_if<
|
---|
79 | is_convertible<T, char const*>
|
---|
80 | , mpl::identity<char const*>
|
---|
81 | , mpl::eval_if<
|
---|
82 | is_convertible<T, wchar_t const*>
|
---|
83 | , mpl::identity<wchar_t const*>
|
---|
84 | , mpl::identity<T>
|
---|
85 | >
|
---|
86 | >
|
---|
87 | , mpl::identity<T>
|
---|
88 | >::type
|
---|
89 | type;
|
---|
90 | };
|
---|
91 |
|
---|
92 | template <typename T>
|
---|
93 | struct as_tuple_element
|
---|
94 | {
|
---|
95 | typedef typename
|
---|
96 | mpl::eval_if<
|
---|
97 | is_reference_wrapper<T>
|
---|
98 | , add_reference<typename unwrap_reference<T>::type>
|
---|
99 | , maybe_string<T>
|
---|
100 | >::type
|
---|
101 | type;
|
---|
102 | };
|
---|
103 |
|
---|
104 | #endif
|
---|
105 |
|
---|
106 | }}}
|
---|
107 |
|
---|
108 | #endif
|
---|