string_view.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2015 MongoDB Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <bsoncxx/config/prelude.hpp>
  16. #if defined(BSONCXX_POLY_USE_MNMLSTC)
  17. #if defined(MONGO_CXX_DRIVER_COMPILING) || defined(BSONCXX_POLY_USE_SYSTEM_MNMLSTC)
  18. #include <core/string.hpp>
  19. #else
  20. #include <bsoncxx/third_party/mnmlstc/core/string.hpp>
  21. #endif
  22. namespace bsoncxx {
  23. BSONCXX_INLINE_NAMESPACE_BEGIN
  24. namespace stdx {
  25. using ::core::basic_string_view;
  26. using ::core::string_view;
  27. } // namespace stdx
  28. BSONCXX_INLINE_NAMESPACE_END
  29. } // namespace bsoncxx
  30. #elif defined(BSONCXX_POLY_USE_BOOST)
  31. #include <boost/version.hpp>
  32. #if BOOST_VERSION >= 106100
  33. #include <boost/utility/string_view.hpp>
  34. namespace bsoncxx {
  35. BSONCXX_INLINE_NAMESPACE_BEGIN
  36. namespace stdx {
  37. using ::boost::basic_string_view;
  38. using ::boost::string_view;
  39. } // namespace stdx
  40. BSONCXX_INLINE_NAMESPACE_END
  41. } // namespace bsoncxx
  42. #else
  43. #include <boost/utility/string_ref.hpp>
  44. namespace bsoncxx {
  45. BSONCXX_INLINE_NAMESPACE_BEGIN
  46. namespace stdx {
  47. template <typename charT, typename traits = std::char_traits<charT>>
  48. using basic_string_view = ::boost::basic_string_ref<charT, traits>;
  49. using string_view = ::boost::string_ref;
  50. } // namespace stdx
  51. BSONCXX_INLINE_NAMESPACE_END
  52. } // namespace bsoncxx
  53. #endif
  54. #elif defined(BSONCXX_POLY_USE_STD_EXPERIMENTAL)
  55. #include <experimental/string_view>
  56. namespace bsoncxx {
  57. BSONCXX_INLINE_NAMESPACE_BEGIN
  58. namespace stdx {
  59. using ::std::experimental::basic_string_view;
  60. using ::std::experimental::string_view;
  61. } // namespace stdx
  62. BSONCXX_INLINE_NAMESPACE_END
  63. } // namespace bsoncxx
  64. #elif defined(BSONCXX_POLY_USE_STD)
  65. #include <string_view>
  66. namespace bsoncxx {
  67. BSONCXX_INLINE_NAMESPACE_BEGIN
  68. namespace stdx {
  69. using ::std::basic_string_view;
  70. using ::std::string_view;
  71. } // namespace stdx
  72. BSONCXX_INLINE_NAMESPACE_END
  73. } // namespace bsoncxx
  74. #else
  75. #error "Cannot find a valid polyfill for string_view"
  76. #endif
  77. #include <bsoncxx/config/postlude.hpp>