optional.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/optional.hpp>
  19. #else
  20. #include <bsoncxx/third_party/mnmlstc/core/optional.hpp>
  21. #endif
  22. namespace bsoncxx {
  23. BSONCXX_INLINE_NAMESPACE_BEGIN
  24. namespace stdx {
  25. using ::core::optional;
  26. using ::core::nullopt;
  27. using ::core::make_optional;
  28. } // namespace stdx
  29. BSONCXX_INLINE_NAMESPACE_END
  30. } // namespace bsoncxx
  31. #elif defined(BSONCXX_POLY_USE_BOOST)
  32. #include <boost/none.hpp>
  33. #include <boost/optional/optional.hpp>
  34. namespace bsoncxx {
  35. BSONCXX_INLINE_NAMESPACE_BEGIN
  36. namespace stdx {
  37. using ::boost::optional;
  38. using nullopt_t = ::boost::none_t;
  39. // TODO(MSVC): This would be better expressed as constexpr, but VS2015U1 can't do it.
  40. const nullopt_t nullopt{::boost::none};
  41. using ::boost::make_optional;
  42. } // namespace stdx
  43. BSONCXX_INLINE_NAMESPACE_END
  44. } // namespace bsoncxx
  45. #elif defined(BSONCXX_POLY_USE_STD_EXPERIMENTAL)
  46. #include <experimental/optional>
  47. namespace bsoncxx {
  48. BSONCXX_INLINE_NAMESPACE_BEGIN
  49. namespace stdx {
  50. using ::std::experimental::optional;
  51. using ::std::experimental::nullopt;
  52. using ::std::experimental::make_optional;
  53. } // namespace stdx
  54. BSONCXX_INLINE_NAMESPACE_END
  55. } // namespace bsoncxx
  56. #elif defined(BSONCXX_POLY_USE_STD)
  57. #include <optional>
  58. namespace bsoncxx {
  59. BSONCXX_INLINE_NAMESPACE_BEGIN
  60. namespace stdx {
  61. using ::std::optional;
  62. using ::std::nullopt;
  63. using ::std::make_optional;
  64. } // namespace stdx
  65. BSONCXX_INLINE_NAMESPACE_END
  66. } // namespace bsoncxx
  67. #else
  68. #error "Cannot find a valid polyfill for optional"
  69. #endif
  70. #include <bsoncxx/config/postlude.hpp>