s_.ipp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef BOOST_MATH_S__HPP
  2. #define BOOST_MATH_S__HPP
  3. // Copyright (c) 2006 Johan Rade
  4. // Copyright (c) 2012 Paul A. Bristow
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt
  7. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. // The macro S_ lets you write
  9. //
  10. // basic_string<CharType> s = S_("foo");
  11. // and
  12. // CharType c = S_('a');
  13. //
  14. // provided that CharType is either char or wchar_t.
  15. // Used by tests of output of signed zero and others.
  16. #ifdef _MSC_VER
  17. # pragma warning(push)
  18. # pragma warning(disable : 4512) // conditional expression is constant.
  19. #endif
  20. #include <string>
  21. //------------------------------------------------------------------------------
  22. #define S_(a) make_literal_helper(a, L##a)
  23. class char_literal_helper {
  24. public:
  25. char_literal_helper(char c, wchar_t wc) : c_(c), wc_(wc) {}
  26. operator char() { return c_; }
  27. operator wchar_t() { return wc_; }
  28. private:
  29. const char c_;
  30. const wchar_t wc_;
  31. };
  32. class string_literal_helper {
  33. public:
  34. string_literal_helper(const char* s, const wchar_t* ws) : s_(s), ws_(ws) {}
  35. operator std::string() { return s_; }
  36. operator std::wstring() { return ws_; }
  37. private:
  38. const char* s_;
  39. const wchar_t* ws_;
  40. };
  41. inline char_literal_helper make_literal_helper(char c, wchar_t wc)
  42. {
  43. return char_literal_helper(c, wc);
  44. }
  45. inline string_literal_helper make_literal_helper(const char* s, const wchar_t* ws)
  46. {
  47. return string_literal_helper(s, ws);
  48. }
  49. //------------------------------------------------------------------------------
  50. #ifdef _MSC_VER
  51. # pragma warning(pop)
  52. #endif
  53. #endif // BOOST_MATH_S__HPP