1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | // literals.hpp |
---|
3 | // |
---|
4 | // Copyright 2004 Eric Niebler. Distributed under the Boost |
---|
5 | // Software License, Version 1.0. (See accompanying file |
---|
6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | |
---|
8 | #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_LITERALS_HPP_EAN_10_04_2005 |
---|
9 | #define BOOST_XPRESSIVE_DETAIL_UTILITY_LITERALS_HPP_EAN_10_04_2005 |
---|
10 | |
---|
11 | // MS compatible compilers support #pragma once |
---|
12 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
13 | # pragma once |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <boost/config.hpp> // for BOOST_STATIC_CONSTANT |
---|
17 | #include <boost/detail/workaround.hpp> |
---|
18 | |
---|
19 | namespace boost { namespace xpressive { namespace detail |
---|
20 | { |
---|
21 | |
---|
22 | /////////////////////////////////////////////////////////////////////////////// |
---|
23 | // char_literal |
---|
24 | // |
---|
25 | template<typename Char, char Ch, wchar_t Wch> |
---|
26 | struct char_literal; |
---|
27 | |
---|
28 | template<char Ch, wchar_t Wch> |
---|
29 | struct char_literal<char, Ch, Wch> |
---|
30 | { |
---|
31 | BOOST_STATIC_CONSTANT(char, value = Ch); |
---|
32 | }; |
---|
33 | |
---|
34 | template<char Ch, wchar_t Wch> |
---|
35 | struct char_literal<wchar_t, Ch, Wch> |
---|
36 | { |
---|
37 | BOOST_STATIC_CONSTANT(wchar_t, value = Wch); |
---|
38 | }; |
---|
39 | |
---|
40 | #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION |
---|
41 | template<char Ch, wchar_t Wch> |
---|
42 | char const char_literal<char, Ch, Wch>::value; |
---|
43 | |
---|
44 | template<char Ch, wchar_t Wch> |
---|
45 | wchar_t const char_literal<wchar_t, Ch, Wch>::value; |
---|
46 | #endif |
---|
47 | |
---|
48 | template<typename Ch> |
---|
49 | struct string_literal; |
---|
50 | |
---|
51 | template<> |
---|
52 | struct string_literal<char> |
---|
53 | { |
---|
54 | static char const *pick(char const *cstr, wchar_t const *) |
---|
55 | { |
---|
56 | return cstr; |
---|
57 | } |
---|
58 | |
---|
59 | static char pick(char ch, wchar_t) |
---|
60 | { |
---|
61 | return ch; |
---|
62 | } |
---|
63 | }; |
---|
64 | |
---|
65 | template<> |
---|
66 | struct string_literal<wchar_t> |
---|
67 | { |
---|
68 | static wchar_t const *pick(char const *, wchar_t const *cstr) |
---|
69 | { |
---|
70 | return cstr; |
---|
71 | } |
---|
72 | |
---|
73 | static wchar_t pick(char, wchar_t ch) |
---|
74 | { |
---|
75 | return ch; |
---|
76 | } |
---|
77 | }; |
---|
78 | |
---|
79 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) |
---|
80 | |
---|
81 | # define BOOST_XPR_CHAR_(Char, ch) ch |
---|
82 | # define BOOST_XPR_CSTR_(Char, st) boost::xpressive::detail::string_literal<Char>::pick(st, L##st) |
---|
83 | |
---|
84 | #else |
---|
85 | |
---|
86 | # define BOOST_XPR_CHAR_(Char, ch) boost::xpressive::detail::char_literal<Char, ch, L##ch>::value |
---|
87 | # define BOOST_XPR_CSTR_(Char, st) boost::xpressive::detail::string_literal<Char>::pick(st, L##st) |
---|
88 | |
---|
89 | #endif |
---|
90 | |
---|
91 | }}} // namespace boost::xpressive::detail |
---|
92 | |
---|
93 | #endif |
---|