literals.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // literals.hpp
  3. //
  4. // Copyright 2008 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. #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_LITERALS_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_UTILITY_LITERALS_HPP_EAN_10_04_2005
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER)
  11. # pragma once
  12. #endif
  13. #include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
  14. #include <boost/cstdint.hpp> // for BOOST_STATIC_CONSTANT
  15. #include <boost/detail/workaround.hpp>
  16. namespace boost { namespace xpressive { namespace detail
  17. {
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // char_literal
  20. //
  21. template<typename Char, boost::intmax_t Ch, boost::intmax_t Wch>
  22. struct char_literal;
  23. template<typename Char, boost::intmax_t Ch>
  24. struct char_literal<Char, Ch, Ch>
  25. {
  26. BOOST_STATIC_CONSTANT(boost::intmax_t, value = Ch);
  27. };
  28. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  29. template<typename Char, boost::intmax_t Ch>
  30. boost::intmax_t const char_literal<Char, Ch, Ch>::value;
  31. #endif
  32. template<typename Ch>
  33. struct string_literal;
  34. template<>
  35. struct string_literal<char>
  36. {
  37. static BOOST_CONSTEXPR char const *pick(char const *cstr, wchar_t const *)
  38. {
  39. return cstr;
  40. }
  41. static BOOST_CONSTEXPR char pick(char ch, wchar_t)
  42. {
  43. return ch;
  44. }
  45. };
  46. template<>
  47. struct string_literal<wchar_t>
  48. {
  49. static BOOST_CONSTEXPR wchar_t const *pick(char const *, wchar_t const *cstr)
  50. {
  51. return cstr;
  52. }
  53. static BOOST_CONSTEXPR wchar_t pick(char, wchar_t ch)
  54. {
  55. return ch;
  56. }
  57. };
  58. #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
  59. # define BOOST_XPR_CHAR_(Char, ch) ch
  60. # define BOOST_XPR_CSTR_(Char, st) boost::xpressive::detail::string_literal<Char>::pick(st, L##st)
  61. #else
  62. # define BOOST_XPR_CHAR_(Char, ch) boost::xpressive::detail::char_literal<Char, ch, L##ch>::value
  63. # define BOOST_XPR_CSTR_(Char, st) boost::xpressive::detail::string_literal<Char>::pick(st, L##st)
  64. #endif
  65. }}} // namespace boost::xpressive::detail
  66. #endif