cxx11_char_types.hpp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // boost cxx11_char_types.hpp --------------------------------------------------------//
  2. // Copyright Beman Dawes 2011
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. //--------------------------------------------------------------------------------------//
  6. // //
  7. // The purpose of this header is to emulate the C++11 char16_t and char32_t //
  8. // character and string types so that they can be used in both C++11 and C++03 //
  9. // programs. //
  10. // //
  11. // The emulation names use char16/char32 rather than char16_t/char32_t to avoid use //
  12. // of names that are keywords in C++11. //
  13. // //
  14. // The emulation names are placed in namespace boost, as is usual for Boost C++11 //
  15. // emulation names such as those in header <boost/cstdint.hpp>. //
  16. // //
  17. // An alternative would would have been to place the C++11 emulation names at global //
  18. // scope, and put the C++11 string types in namespace std. That is the approach taken //
  19. // by Microsoft Visual Studio 2010, but is controversion with some Boost users and //
  20. // developers, and runs counter to usual Boost practice. //
  21. // //
  22. // Thanks to Mathias Gaunard and others for discussions leading to the final form //
  23. // of these typedefs. //
  24. // //
  25. // Boost C++11 C++03 //
  26. // ---------------- -------------- -------------------------------- //
  27. // boost::char16 char16_t uint16_t //
  28. // boost::char32 char32_t uint32_t //
  29. // boost::u16string std::u16string std::basic_string<boost::char16> //
  30. // boost::u32string std::u32string std::basic_string<boost::char32> //
  31. // //
  32. // Uses the typedefs provided by Microsoft Visual C++ 2010 if present //
  33. // //
  34. // Thanks to Mathias Gaunard and others for discussions leading to the final form //
  35. // of these typedefs. //
  36. // //
  37. //--------------------------------------------------------------------------------------//
  38. #if !defined(BOOST_CXX11_CHAR_TYPES_HPP)
  39. # define BOOST_CXX11_CHAR_TYPES_HPP
  40. # include <boost/config.hpp>
  41. # include <boost/cstdint.hpp>
  42. # include <string>
  43. namespace boost
  44. {
  45. # if defined(BOOST_NO_CXX11_CHAR16_T) && (!defined(_MSC_VER) || _MSC_VER < 1600) // 1600 == VC++10
  46. typedef boost::uint_least16_t char16;
  47. typedef std::basic_string<boost::char16> u16string;
  48. # else
  49. typedef char16_t char16;
  50. typedef std::u16string u16string;
  51. # endif
  52. # if defined(BOOST_NO_CXX11_CHAR32_T) && (!defined(_MSC_VER) || _MSC_VER < 1600) // 1600 == VC++10
  53. typedef boost::uint_least32_t char32;
  54. typedef std::basic_string<boost::char32> u32string;
  55. # else
  56. typedef char32_t char32;
  57. typedef std::u32string u32string;
  58. # endif
  59. } // namespace boost
  60. #endif // !defined(BOOST_CXX11_CHAR_TYPES_HPP)