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