string_view.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_STRING_VIEW_HPP
  10. #define BOOST_JSON_STRING_VIEW_HPP
  11. #include <boost/json/detail/config.hpp>
  12. #ifndef BOOST_JSON_STANDALONE
  13. # include <boost/utility/string_view.hpp>
  14. #else
  15. # if __has_include(<string_view>)
  16. # include <string_view>
  17. # if __cpp_lib_string_view < 201603L
  18. # error Support for std::string_view is required to use Boost.JSON standalone
  19. # endif
  20. # else
  21. # error Header <string_view> is required to use Boost.JSON standalone
  22. # endif
  23. #endif
  24. #include <type_traits>
  25. BOOST_JSON_NS_BEGIN
  26. #ifdef BOOST_JSON_DOCS
  27. /** The type of string view used by the library.
  28. This type alias is set depending
  29. on how the library is configured:
  30. @par Use with Boost
  31. If the macro `BOOST_JSON_STANDALONE` is
  32. not defined, this type will be an alias
  33. for `boost::string_view`.
  34. Compiling a program using the library will
  35. require Boost, and a compiler conforming
  36. to C++11 or later.
  37. @par Use without Boost
  38. If the macro `BOOST_JSON_STANDALONE` is
  39. defined, this type will be an alias
  40. for `std::string_view`.
  41. Compiling a program using the library will
  42. require only a compiler conforming to C++17
  43. or later.
  44. @see https://en.cppreference.com/w/cpp/string/basic_string_view
  45. */
  46. using string_view = __see_below__;
  47. #elif ! defined(BOOST_JSON_STANDALONE)
  48. using string_view = boost::string_view;
  49. #else
  50. using string_view = std::string_view;
  51. #endif
  52. namespace detail {
  53. template<class T>
  54. using is_string_viewish = typename std::enable_if<
  55. std::is_convertible<
  56. T const&, string_view>::value &&
  57. ! std::is_convertible<
  58. T const&, char const*>::value
  59. >::type;
  60. } // detail
  61. BOOST_JSON_NS_END
  62. #endif