diff --git a/.clang-format b/.clang-format index 7cf63c1ad3..f6721e7926 100644 --- a/.clang-format +++ b/.clang-format @@ -83,8 +83,8 @@ AttributeMacros: - BSONCXX_ABI_NO_EXPORT - BSONCXX_DEPRECATED - BSONCXX_ENUM - - BSONCXX_PRAGMA - - BSONCXX_RETURNS + - BSONCXX_PRIVATE_PRAGMA + - BSONCXX_PRIVATE_RETURNS - MONGOCXX_ABI_CDECL - MONGOCXX_ABI_EXPORT - MONGOCXX_ABI_NO_EXPORT @@ -144,24 +144,40 @@ IncludeBlocks: Regroup IncludeCategories: - Regex: '".*"' # relative headers Priority: 10 + - Regex: 'bsoncxx/v1/.*/prelude\.hpp' # v1 preludes + Priority: 20 + - Regex: 'mongocxx/v1/.*/prelude\.hpp' # v1 preludes + Priority: 21 + - Regex: 'bsoncxx/v1/.*(-|\/)fwd\.hpp' # v1 forward headers + Priority: 22 + - Regex: 'mongocxx/v1/.*(-|\/)fwd\.hpp' # v1 forward headers + Priority: 23 + - Regex: 'bsoncxx/v1/.*\.hpp' # v1 public headers + Priority: 24 + - Regex: 'mongocxx/v1/.*\.hpp' # v1 public headers + Priority: 25 + - Regex: 'bsoncxx/v1/.*\.hh' # v1 private headers + Priority: 26 + - Regex: 'mongocxx/v1/.*\.hh' # v1 private headers + Priority: 27 - Regex: 'bsoncxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes - Priority: 50 + Priority: 60 - Regex: 'mongocxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes - Priority: 51 + Priority: 61 - Regex: 'bsoncxx/test/.*' # test headers - Priority: 60 + Priority: 70 - Regex: 'mongocxx/test/.*' # test headers - Priority: 61 + Priority: 71 - Regex: '<[[:alnum:]_.]+>' # system headers - Priority: 20 - - Regex: 'bsoncxx/.*(-|\/)fwd\.(hpp|hh)' # all driver forwarding headers Priority: 30 - - Regex: 'mongocxx/.*(-|\/)fwd\.(hpp|hh)' # all driver forwarding headers - Priority: 31 - - Regex: 'bsoncxx/.*' # all remaining (normal) driver headers + - Regex: 'bsoncxx/.*(-|\/)fwd\.(hpp|hh)' # all remaining forward headers Priority: 40 - - Regex: 'mongocxx/.*' # all remaining (normal) driver headers + - Regex: 'mongocxx/.*(-|\/)fwd\.(hpp|hh)' # all remaining forward headers Priority: 41 + - Regex: 'bsoncxx/.*' # all remaining headers + Priority: 50 + - Regex: 'mongocxx/.*' # all remaining headers + Priority: 51 - Regex: '.*' # all other headers (third party) Priority: 90 IncludeIsMainRegex: '([-_](test|unittest))?$' @@ -274,14 +290,14 @@ SpacesInSquareBrackets: false Standard: Cpp11 StatementAttributeLikeMacros: [] StatementMacros: - - BSONCXX_DISABLE_WARNING - - BSONCXX_FORCE_SEMICOLON - - BSONCXX_IF_CLANG - - BSONCXX_IF_GCC - - BSONCXX_IF_GNU_LIKE - - BSONCXX_IF_MSVC - - BSONCXX_POP_WARNINGS - - BSONCXX_PUSH_WARNINGS + - BSONCXX_PRIVATE_FORCE_SEMICOLON + - BSONCXX_PRIVATE_IF_CLANG + - BSONCXX_PRIVATE_IF_GCC + - BSONCXX_PRIVATE_IF_GNU_LIKE + - BSONCXX_PRIVATE_IF_MSVC + - BSONCXX_PRIVATE_WARNINGS_DISABLE + - BSONCXX_PRIVATE_WARNINGS_POP + - BSONCXX_PRIVATE_WARNINGS_PUSH - BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN - BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END TableGenBreakInsideDAGArg: DontBreak diff --git a/examples/bsoncxx/getting_values.cpp b/examples/bsoncxx/getting_values.cpp index 36816bf666..cb450b3fde 100644 --- a/examples/bsoncxx/getting_values.cpp +++ b/examples/bsoncxx/getting_values.cpp @@ -72,7 +72,7 @@ int EXAMPLES_CDECL main() { auto invalid1 = doc["name"]["middle"]; auto invalid2 = doc["contribs"][1000]; if (invalid1 || invalid2) { - BSONCXX_UNREACHABLE; // Not reached. + return EXIT_FAILURE; // Not reached. } // Similarly, indexed access (either by string or numeric index) into a type that is not @@ -81,7 +81,7 @@ int EXAMPLES_CDECL main() { auto invalid3 = doc["_id"]["invalid"]; auto invalid4 = doc["name"][3]; if (invalid3 || invalid4) { - BSONCXX_UNREACHABLE; // Not reached. + return EXIT_FAILURE; // Not reached. } // Values are accessed through get_*() methods. diff --git a/src/bsoncxx/CMakeLists.txt b/src/bsoncxx/CMakeLists.txt index 7e8057fe13..1d4dcafe53 100644 --- a/src/bsoncxx/CMakeLists.txt +++ b/src/bsoncxx/CMakeLists.txt @@ -192,14 +192,14 @@ if(1) BASE_NAME BSONCXX_ABI EXPORT_MACRO_NAME BSONCXX_ABI_EXPORT DEPRECATED_MACRO_NAME BSONCXX_DEPRECATED - EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/bsoncxx/v_noabi/bsoncxx/config/export.hpp + EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/bsoncxx/v1/config/export.hpp STATIC_DEFINE BSONCXX_STATIC CUSTOM_CONTENT_FROM_VARIABLE bsoncxx_export_header_custom_content ) install(FILES - ${PROJECT_BINARY_DIR}/lib/bsoncxx/v_noabi/bsoncxx/config/export.hpp - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/v_noabi/bsoncxx/config + ${PROJECT_BINARY_DIR}/lib/bsoncxx/v1/config/export.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/v1/config COMPONENT dev ) endfunction() diff --git a/src/bsoncxx/include/bsoncxx/docs/v1.hpp b/src/bsoncxx/include/bsoncxx/docs/v1.hpp new file mode 100644 index 0000000000..566cd66653 --- /dev/null +++ b/src/bsoncxx/include/bsoncxx/docs/v1.hpp @@ -0,0 +1,56 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#if !defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR) +#error "This file is for documentation purposes only. It should not be included." +#endif // !defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR) + +/// +/// @file +/// For documentation purposes only. +/// +/// @note This header is not includable! +/// + +/// +/// @dir bsoncxx/v1 +/// Provides headers declaring entities in @ref bsoncxx::v1. +/// + +/// +/// @dir bsoncxx/v1/config +/// Provides headers related to bsoncxx library configuration. +/// + +/// +/// @dir bsoncxx/v1/detail +/// Provides headers for internal use only. +/// +/// @warning For internal use only! +/// + +/// +/// @dir bsoncxx/v1/stdx +/// Provides headers declaring entities in @ref bsoncxx::v1::stdx. +/// + +/// +/// @namespace bsoncxx::v1 +/// Declares entities whose ABI stability is guaranteed for documented symbols. +/// + +/// +/// @namespace bsoncxx::v1::stdx +/// @copydoc bsoncxx::stdx +/// diff --git a/src/bsoncxx/include/bsoncxx/docs/v_noabi.hpp b/src/bsoncxx/include/bsoncxx/docs/v_noabi.hpp index 551092636d..a9275ae284 100644 --- a/src/bsoncxx/include/bsoncxx/docs/v_noabi.hpp +++ b/src/bsoncxx/include/bsoncxx/docs/v_noabi.hpp @@ -25,11 +25,10 @@ /// /// @dir bsoncxx/v_noabi -/// The directory relative to which headers declaring entities in @ref bsoncxx::v_noabi are -/// typically included. +/// Provides headers declaring entities in @ref bsoncxx::v_noabi. /// -/// For backward compatibility, unstable ABI headers may be included using the syntax -/// ``, which is equivalent to ``. +/// Unstable ABI headers may be included using the syntax ``, which is equivalent to +/// ``. /// /// diff --git a/src/bsoncxx/include/bsoncxx/v1/detail/compare.hpp b/src/bsoncxx/include/bsoncxx/v1/detail/compare.hpp new file mode 100644 index 0000000000..e38ee65b79 --- /dev/null +++ b/src/bsoncxx/include/bsoncxx/v1/detail/compare.hpp @@ -0,0 +1,176 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include +#include + +#include +#include +#include + +namespace bsoncxx { +namespace detail { + +// Callable object and tag type for equality comparison. +struct equal_to { + template + constexpr requires_t> operator()(L&& l, R&& r) const noexcept(noexcept(l == r)) { + return l == r; + } +}; + +// Derive from this class to define ADL-only operator== and operator!= on the basis of +// an ADL-only tag_invoke(equal_to, l, r). +class equality_operators { + template + constexpr static auto impl(rank<1>, L& l, R& r) BSONCXX_PRIVATE_RETURNS(tag_invoke(equal_to{}, l, r)); + + template + constexpr static auto impl(rank<0>, L& l, R& r) BSONCXX_PRIVATE_RETURNS(tag_invoke(equal_to{}, r, l)); + + // @cond DOXYGEN_DISABLE "Found ';' while parsing initializer list!" + template + constexpr friend auto operator==(Left const& self, Other const& other) + BSONCXX_PRIVATE_RETURNS(equality_operators::impl(rank<1>{}, self, other)); + // @endcond + + // @cond DOXYGEN_DISABLE "Found ';' while parsing initializer list!" + template + constexpr friend auto operator!=(Left const& self, Other const& other) + BSONCXX_PRIVATE_RETURNS(!equality_operators::impl(rank<1>{}, self, other)); + // @endcond +}; + +// Very basic impl of C++20 std::strong_ordering. +// +// We don't need other weaker orderings yet, so this is all that we have. +class strong_ordering { + signed char _c; + struct _construct {}; + + constexpr strong_ordering(_construct, signed char c) noexcept : _c(c) {} + + public: + static strong_ordering const less; + static strong_ordering const greater; + static strong_ordering const equivalent; + static strong_ordering const equal; + + constexpr strong_ordering(std::nullptr_t) noexcept : strong_ordering(_construct{}, 0) {} + + constexpr bool operator==(strong_ordering o) const noexcept { + return _c == o._c; + } + constexpr bool operator!=(strong_ordering o) const noexcept { + return !(*this == o); + } +#pragma push_macro("DEFOP") +#undef DEFOP +#define DEFOP(Op) \ + constexpr bool operator Op(std::nullptr_t) const noexcept { \ + return _c Op 0; \ + } \ + static_assert(true, "") + DEFOP(<); + DEFOP(>); + DEFOP(<=); + DEFOP(>=); +#pragma pop_macro("DEFOP") + + // nonstd: Swap greater/less values + constexpr strong_ordering inverted() const noexcept { + return *this < nullptr ? greater : *this > nullptr ? less : *this; + } +}; + +#pragma push_macro("INLINE_VAR") +#undef INLINE_VAR +#define INLINE_VAR \ + BSONCXX_PRIVATE_IF_GNU_LIKE([[gnu::weak]]) \ + BSONCXX_PRIVATE_IF_MSVC(__declspec(selectany)) + +INLINE_VAR const strong_ordering strong_ordering::less = strong_ordering(strong_ordering::_construct{}, -1); +INLINE_VAR const strong_ordering strong_ordering::greater = strong_ordering(strong_ordering::_construct{}, 1); +INLINE_VAR const strong_ordering strong_ordering::equivalent = strong_ordering(strong_ordering::_construct{}, 0); +INLINE_VAR const strong_ordering strong_ordering::equal = strong_ordering(strong_ordering::_construct{}, 0); + +#pragma pop_macro("INLINE_VAR") + +// Implements a three-way comparison between two objects. That is, in +// a single operation, determine whether the left operand is less-than, greater-than, +// or equal-to the right-hand operand. +struct compare_three_way { + BSONCXX_PRIVATE_WARNINGS_PUSH(); + BSONCXX_PRIVATE_WARNINGS_DISABLE(GNU("-Wfloat-equal")); + template < + typename L, + typename R, + typename = decltype(std::declval() < std::declval()), + typename = decltype(std::declval() == std::declval())> + constexpr static strong_ordering impl(L const& l, R const& r, rank<1>) { + return (l < r) ? strong_ordering::less : (l == r ? strong_ordering::equal : strong_ordering::greater); + } + BSONCXX_PRIVATE_WARNINGS_POP(); + + template < + typename L, + typename R, + typename = decltype(tag_invoke(std::declval(), std::declval(), std::declval()))> + constexpr static strong_ordering impl(L const& l, R const& r, rank<2>) { + return tag_invoke(compare_three_way{}, l, r); + } + + template + constexpr auto operator()(L const& l, R const& r) const BSONCXX_PRIVATE_RETURNS((impl)(l, r, rank<2>{})); +}; + +// Inherit to define ADL-visible ordering operators based on an ADL-visible +// implementation of tag_invoke(compare_three_way, l, r). +struct ordering_operators { + template + constexpr static auto impl(L const& l, R const& r, rank<1>) + BSONCXX_PRIVATE_RETURNS(tag_invoke(compare_three_way{}, l, r)); + + template + constexpr static auto impl(L const& l, R const& r, rank<0>) + BSONCXX_PRIVATE_RETURNS(tag_invoke(compare_three_way{}, r, l).inverted()); + +#pragma push_macro("DEFOP") +#undef DEFOP +#define DEFOP(Oper) \ + template \ + constexpr friend auto operator Oper(L const& l, R const& r) \ + BSONCXX_PRIVATE_RETURNS(ordering_operators::impl(l, r, rank<1>{}) Oper nullptr) + DEFOP(<); + DEFOP(>); + DEFOP(<=); + DEFOP(>=); +#pragma pop_macro("DEFOP") +}; + +} // namespace detail +} // namespace bsoncxx + +#include + +/// +/// @file +/// For internal use only! +/// +/// @warning For internal use only! +/// diff --git a/src/bsoncxx/include/bsoncxx/v1/detail/macros.hpp b/src/bsoncxx/include/bsoncxx/v1/detail/macros.hpp new file mode 100644 index 0000000000..d70cba09c1 --- /dev/null +++ b/src/bsoncxx/include/bsoncxx/v1/detail/macros.hpp @@ -0,0 +1,163 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Traditional include guard is required to support v_noabi include-via-prelude. +#if !defined(BSONCXX_V1_DETAIL_MACROS_HPP) +#define BSONCXX_V1_DETAIL_MACROS_HPP + +// Convert the given macro argument to a string literal, after macro expansion. +#define BSONCXX_PRIVATE_STRINGIFY(...) BSONCXX_PRIVATE_STRINGIFY_IMPL(__VA_ARGS__) +#define BSONCXX_PRIVATE_STRINGIFY_IMPL(...) #__VA_ARGS__ + +// Token-paste two macro arguments, after macro expansion +#define BSONCXX_PRIVATE_CONCAT(A, ...) BSONCXX_PRIVATE_CONCAT_IMPL(A, __VA_ARGS__) +#define BSONCXX_PRIVATE_CONCAT_IMPL(A, ...) A##__VA_ARGS__ + +// Expands to a _Pragma() preprocessor directive, after macro expansion +// +// The arguments an arbitrary "token soup", and should not be quoted like a regular +// _Pragma. This macro will stringify-them itself. +// +// Example: +// +// BSONCXX_PRIVATE_PRAGMA(GCC diagnostic ignore "-Wconversion") +// +// will become: +// +// _Pragma("GCC diagnostic ignore \"-Wconversion\"") +// +#define BSONCXX_PRIVATE_PRAGMA(...) BSONCXX_PRIVATE_PRAGMA_IMPL(__VA_ARGS__) +#ifdef _MSC_VER +// Old MSVC doesn't recognize C++11 _Pragma(), but it always recognized __pragma +#define BSONCXX_PRIVATE_PRAGMA_IMPL(...) __pragma(__VA_ARGS__) +#else +#define BSONCXX_PRIVATE_PRAGMA_IMPL(...) _Pragma(BSONCXX_PRIVATE_STRINGIFY(__VA_ARGS__)) +#endif + +// Use in a declaration position to force the appearence of a semicolon +// as the next token. Use this for statement-like or declaration-like macros to +// enforce that their call sites are followed by a semicolon +#define BSONCXX_PRIVATE_FORCE_SEMICOLON static_assert(true, "") + +// Add a trailing noexcept, decltype-return, and return-body to a +// function definition. (Not compatible with lambda expressions.) +// +// Example: +// +// template +// auto foo(T x, T y) BSONCXX_PRIVATE_RETURNS(x + y); +// +// Becomes: +// +// template +// auto foo(T x, T y) noexcept(noexcept(x + y)) +// -> decltype(x + y) +// { return x + y }; +// +#define BSONCXX_PRIVATE_RETURNS(...) \ + noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { \ + return __VA_ARGS__; \ + } \ + BSONCXX_PRIVATE_FORCE_SEMICOLON + +// @macro mongocxx_cxx14_constexpr +// Expands to `constexpr` if compiling as c++14 or greater, otherwise +// expands to `inline`. +// +// Use this on functions that can only be constexpr in C++14 or newer, including +// non-const member functions. +#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L && _MSC_VER > 1910) +#define BSONCXX_PRIVATE_CONSTEXPR_CXX14 constexpr +#else +#define BSONCXX_PRIVATE_CONSTEXPR_CXX14 inline +#endif + +#define BSONCXX_PRIVATE_IF_MSVC(...) +#define BSONCXX_PRIVATE_IF_GCC(...) +#define BSONCXX_PRIVATE_IF_CLANG(...) +#define BSONCXX_PRIVATE_IF_GNU_LIKE(...) \ + BSONCXX_PRIVATE_IF_GCC(__VA_ARGS__) \ + BSONCXX_PRIVATE_IF_CLANG(__VA_ARGS__) + +// clang-format off +#ifdef __GNUC__ + #ifdef __clang__ + #undef BSONCXX_PRIVATE_IF_CLANG + #define BSONCXX_PRIVATE_IF_CLANG(...) __VA_ARGS__ + #else + #undef BSONCXX_PRIVATE_IF_GCC + #define BSONCXX_PRIVATE_IF_GCC(...) __VA_ARGS__ + #endif +#elif defined(_MSC_VER) + #undef BSONCXX_PRIVATE_IF_MSVC + #define BSONCXX_PRIVATE_IF_MSVC(...) __VA_ARGS__ +#endif +// clang-format on + +// Disable a warning for a particular compiler. +// +// The argument should be of the form: +// +// - Clang() +// - GCC() +// - GNU() +// - MSVC() +// +// The "GNU" form applies to both GCC and Clang +#define BSONCXX_PRIVATE_WARNINGS_DISABLE(Spec) \ + BSONCXX_PRIVATE_CONCAT(BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_, Spec) \ + BSONCXX_PRIVATE_FORCE_SEMICOLON + +// Push the current compiler diagnostics settings state +#define BSONCXX_PRIVATE_WARNINGS_PUSH() \ + BSONCXX_PRIVATE_IF_GNU_LIKE(BSONCXX_PRIVATE_PRAGMA(GCC diagnostic push)) \ + BSONCXX_PRIVATE_IF_MSVC(BSONCXX_PRIVATE_PRAGMA(warning(push))) \ + BSONCXX_PRIVATE_FORCE_SEMICOLON + +// Restore prior compiler diagnostics settings from before the most +// recent BSONCXX_PRIVATE_WARNINGS_PUSH() +#define BSONCXX_PRIVATE_WARNINGS_POP() \ + BSONCXX_PRIVATE_IF_GNU_LIKE(BSONCXX_PRIVATE_PRAGMA(GCC diagnostic pop)) \ + BSONCXX_PRIVATE_IF_MSVC(BSONCXX_PRIVATE_PRAGMA(warning(pop))) \ + BSONCXX_PRIVATE_FORCE_SEMICOLON + +#define BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GCC(...) \ + BSONCXX_PRIVATE_IF_GCC(BSONCXX_PRIVATE_PRAGMA(GCC diagnostic ignored __VA_ARGS__)) + +#define BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_Clang(...) \ + BSONCXX_PRIVATE_IF_CLANG(BSONCXX_PRIVATE_PRAGMA(GCC diagnostic ignored __VA_ARGS__)) + +#define BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GNU(...) \ + BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GCC(__VA_ARGS__) \ + BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_Clang(__VA_ARGS__) + +#define BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_MSVC(...) \ + BSONCXX_PRIVATE_IF_MSVC(BSONCXX_PRIVATE_PRAGMA(warning(disable : __VA_ARGS__))) + +#define BSONCXX_PRIVATE_FWD(...) static_cast(__VA_ARGS__) + +#define BSONCXX_PRIVATE_UNREACHABLE \ + if (1) { \ + std::abort(); \ + } else \ + ((void)0) + +#endif // BSONCXX_V1_DETAIL_MACROS_HPP + +/// +/// @file +/// For internal use only! +/// +/// @warning For internal use only! +/// diff --git a/src/bsoncxx/include/bsoncxx/v1/detail/postlude.hpp b/src/bsoncxx/include/bsoncxx/v1/detail/postlude.hpp new file mode 100644 index 0000000000..6174815215 --- /dev/null +++ b/src/bsoncxx/include/bsoncxx/v1/detail/postlude.hpp @@ -0,0 +1,85 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// bsoncxx/v1/config/config.hpp (generated by CMake) +#pragma pop_macro("BSONCXX_V1_CONFIG_CONFIG_HPP") +#if !defined(BSONCXX_V1_CONFIG_CONFIG_HPP) +#pragma pop_macro("BSONCXX_POLY_USE_IMPLS") +#pragma pop_macro("BSONCXX_POLY_USE_STD") +#endif + +// bsoncxx/v1/config/export.hpp (generated by CMake) +#pragma pop_macro("BSONCXX_ABI_EXPORT_H") +#if !defined(BSONCXX_ABI_EXPORT_H) +#pragma pop_macro("BSONCXX_ABI_EXPORT") +#pragma pop_macro("BSONCXX_ABI_NO_EXPORT") +#pragma pop_macro("BSONCXX_ABI_CDECL") +#pragma pop_macro("BSONCXX_ABI_EXPORT_CDECL") +#pragma pop_macro("BSONCXX_DEPRECATED") +#endif + +// bsoncxx/v1/config/version.hpp (generated by CMake) +#pragma pop_macro("BSONCXX_V1_CONFIG_VERSION_HPP") +#if !defined(BSONCXX_V1_CONFIG_VERSION_HPP) +#pragma pop_macro("BSONCXX_VERSION_STRING") +#pragma pop_macro("BSONCXX_VERSION_MAJOR") +#pragma pop_macro("BSONCXX_VERSION_MINOR") +#pragma pop_macro("BSONCXX_VERSION_PATCH") +#pragma pop_macro("BSONCXX_VERSION_EXTRA") +#endif + +// bsoncxx/v1/detail/macros.hpp +#pragma pop_macro("BSONCXX_V1_DETAIL_MACROS_HPP") +#if !defined(BSONCXX_V1_DETAIL_MACROS_HPP) +#pragma pop_macro("BSONCXX_PRIVATE_CONCAT_IMPL") +#pragma pop_macro("BSONCXX_PRIVATE_CONCAT") +#pragma pop_macro("BSONCXX_PRIVATE_CONSTEXPR_CXX14") +#pragma pop_macro("BSONCXX_PRIVATE_FORCE_SEMICOLON") +#pragma pop_macro("BSONCXX_PRIVATE_FWD") +#pragma pop_macro("BSONCXX_PRIVATE_IF_CLANG") +#pragma pop_macro("BSONCXX_PRIVATE_IF_GCC") +#pragma pop_macro("BSONCXX_PRIVATE_IF_GNU_LIKE") +#pragma pop_macro("BSONCXX_PRIVATE_IF_MSVC") +#pragma pop_macro("BSONCXX_PRIVATE_PRAGMA_IMPL") +#pragma pop_macro("BSONCXX_PRIVATE_PRAGMA") +#pragma pop_macro("BSONCXX_PRIVATE_RETURNS") +#pragma pop_macro("BSONCXX_PRIVATE_STRINGIFY_IMPL") +#pragma pop_macro("BSONCXX_PRIVATE_STRINGIFY") +#pragma pop_macro("BSONCXX_PRIVATE_UNREACHABLE") +#pragma pop_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_Clang") +#pragma pop_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GCC") +#pragma pop_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GNU") +#pragma pop_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_MSVC") +#pragma pop_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE") +#pragma pop_macro("BSONCXX_PRIVATE_WARNINGS_POP") +#pragma pop_macro("BSONCXX_PRIVATE_WARNINGS_PUSH") +#endif + +#if !defined(BSONCXX_PRIVATE_V1_INSIDE_MACRO_GUARD_SCOPE) +#error "postlude header included without a matching prelude header" +#endif +#pragma pop_macro("BSONCXX_PRIVATE_V1_INSIDE_MACRO_GUARD_SCOPE") + +/// +/// @file +/// The bsoncxx v1 macro guard postlude header. +/// +/// @warning For internal use only! +/// +/// This header uses macro pragmas to guard macros defined by the bsoncxx library for internal use +/// by "popping" their prior definition onto the stack after use by bsoncxx headers. +/// +/// @see +/// - @ref bsoncxx/v1/detail/prelude.hpp +/// diff --git a/src/bsoncxx/include/bsoncxx/v1/detail/prelude.hpp b/src/bsoncxx/include/bsoncxx/v1/detail/prelude.hpp new file mode 100644 index 0000000000..1a26c3494f --- /dev/null +++ b/src/bsoncxx/include/bsoncxx/v1/detail/prelude.hpp @@ -0,0 +1,118 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma push_macro("BSONCXX_PRIVATE_V1_INSIDE_MACRO_GUARD_SCOPE") +#undef BSONCXX_PRIVATE_V1_INSIDE_MACRO_GUARD_SCOPE +#define BSONCXX_PRIVATE_V1_INSIDE_MACRO_GUARD_SCOPE + +// bsoncxx/v1/config/config.hpp (generated by CMake) +#pragma push_macro("BSONCXX_V1_CONFIG_CONFIG_HPP") +#if !defined(BSONCXX_V1_CONFIG_CONFIG_HPP) +#pragma push_macro("BSONCXX_POLY_USE_IMPLS") +#undef BSONCXX_POLY_USE_IMPLS +#pragma push_macro("BSONCXX_POLY_USE_STD") +#undef BSONCXX_POLY_USE_STD +#endif + +// bsoncxx/v1/config/export.hpp (generated by CMake) +#pragma push_macro("BSONCXX_ABI_EXPORT_H") +#if !defined(BSONCXX_ABI_EXPORT_H) +#pragma push_macro("BSONCXX_ABI_EXPORT") +#undef BSONCXX_ABI_EXPORT +#pragma push_macro("BSONCXX_ABI_NO_EXPORT") +#undef BSONCXX_ABI_NO_EXPORT +#pragma push_macro("BSONCXX_ABI_CDECL") +#undef BSONCXX_ABI_CDECL +#pragma push_macro("BSONCXX_ABI_EXPORT_CDECL") +#undef BSONCXX_ABI_EXPORT_CDECL +#pragma push_macro("BSONCXX_DEPRECATED") +#undef BSONCXX_DEPRECATED +#endif + +// bsoncxx/v1/config/version.hpp (generated by CMake) +#pragma push_macro("BSONCXX_V1_CONFIG_VERSION_HPP") +#if !defined(BSONCXX_V1_CONFIG_VERSION_HPP) +#pragma push_macro("BSONCXX_VERSION_STRING") +#undef BSONCXX_VERSION_STRING +#pragma push_macro("BSONCXX_VERSION_MAJOR") +#undef BSONCXX_VERSION_MAJOR +#pragma push_macro("BSONCXX_VERSION_MINOR") +#undef BSONCXX_VERSION_MINOR +#pragma push_macro("BSONCXX_VERSION_PATCH") +#undef BSONCXX_VERSION_PATCH +#pragma push_macro("BSONCXX_VERSION_EXTRA") +#undef BSONCXX_VERSION_EXTRA +#endif + +// bsoncxx/v1/detail/macros.hpp +#pragma push_macro("BSONCXX_V1_DETAIL_MACROS_HPP") +#if !defined(BSONCXX_V1_DETAIL_MACROS_HPP) +#pragma push_macro("BSONCXX_PRIVATE_CONCAT") +#undef BSONCXX_PRIVATE_CONCAT +#pragma push_macro("BSONCXX_PRIVATE_CONCAT_IMPL") +#undef BSONCXX_PRIVATE_CONCAT_IMPL +#pragma push_macro("BSONCXX_PRIVATE_CONSTEXPR_CXX14") +#undef BSONCXX_PRIVATE_CONSTEXPR_CXX14 +#pragma push_macro("BSONCXX_PRIVATE_FORCE_SEMICOLON") +#undef BSONCXX_PRIVATE_FORCE_SEMICOLON +#pragma push_macro("BSONCXX_PRIVATE_FWD") +#undef BSONCXX_PRIVATE_FWD +#pragma push_macro("BSONCXX_PRIVATE_IF_CLANG") +#undef BSONCXX_PRIVATE_IF_CLANG +#pragma push_macro("BSONCXX_PRIVATE_IF_GCC") +#undef BSONCXX_PRIVATE_IF_GCC +#pragma push_macro("BSONCXX_PRIVATE_IF_GNU_LIKE") +#undef BSONCXX_PRIVATE_IF_GNU_LIKE +#pragma push_macro("BSONCXX_PRIVATE_IF_MSVC") +#undef BSONCXX_PRIVATE_IF_MSVC +#pragma push_macro("BSONCXX_PRIVATE_PRAGMA") +#undef BSONCXX_PRIVATE_PRAGMA +#pragma push_macro("BSONCXX_PRIVATE_PRAGMA_IMPL") +#undef BSONCXX_PRIVATE_PRAGMA_IMPL +#pragma push_macro("BSONCXX_PRIVATE_RETURNS") +#undef BSONCXX_PRIVATE_RETURNS +#pragma push_macro("BSONCXX_PRIVATE_STRINGIFY") +#undef BSONCXX_PRIVATE_STRINGIFY +#pragma push_macro("BSONCXX_PRIVATE_STRINGIFY_IMPL") +#undef BSONCXX_PRIVATE_STRINGIFY_IMPL +#pragma push_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_Clang") +#undef BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_Clang +#pragma push_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GCC") +#undef BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GCC +#pragma push_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GNU") +#undef BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_GNU +#pragma push_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_MSVC") +#undef BSONCXX_PRIVATE_WARNINGS_DISABLE_IMPL_FOR_MSVC +#pragma push_macro("BSONCXX_PRIVATE_WARNINGS_DISABLE") +#undef BSONCXX_PRIVATE_WARNINGS_DISABLE +#pragma push_macro("BSONCXX_PRIVATE_WARNINGS_POP") +#undef BSONCXX_PRIVATE_WARNINGS_POP +#pragma push_macro("BSONCXX_PRIVATE_WARNINGS_PUSH") +#undef BSONCXX_PRIVATE_WARNINGS_PUSH +#pragma push_macro("BSONCXX_PRIVATE_UNREACHABLE") +#undef BSONCXX_PRIVATE_UNREACHABLE +#endif + +/// +/// @file +/// The bsoncxx v1 macro guard prelude header. +/// +/// @warning For internal use only! +/// +/// This header uses macro pragmas to guard macros defined by the bsoncxx library for internal use +/// by "pushing" their prior definition onto the stack before use by bsoncxx headers. +/// +/// @see +/// - @ref bsoncxx/v1/detail/postlude.hpp +/// diff --git a/src/bsoncxx/include/bsoncxx/v1/detail/type_traits.hpp b/src/bsoncxx/include/bsoncxx/v1/detail/type_traits.hpp new file mode 100644 index 0000000000..2113af18c6 --- /dev/null +++ b/src/bsoncxx/include/bsoncxx/v1/detail/type_traits.hpp @@ -0,0 +1,519 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include + +#include +#include + +namespace bsoncxx { +namespace detail { + +// Obtain the nested ::type of the given type argument +template +using type_t = typename T::type; + +// Obtain the value_type member type of the given argument +template +using value_type_t = typename T::value_type; + +template +using enable_if_t = typename std::enable_if::type; + +#pragma push_macro("DECL_ALIAS") +#undef DECL_ALIAS +#define DECL_ALIAS(Name) \ + template \ + using Name##_t = type_t> +DECL_ALIAS(decay); +DECL_ALIAS(make_signed); +DECL_ALIAS(make_unsigned); +DECL_ALIAS(remove_reference); +DECL_ALIAS(remove_const); +DECL_ALIAS(remove_volatile); +DECL_ALIAS(remove_pointer); +DECL_ALIAS(remove_cv); +DECL_ALIAS(add_pointer); +DECL_ALIAS(add_const); +DECL_ALIAS(add_volatile); +DECL_ALIAS(add_lvalue_reference); +DECL_ALIAS(add_rvalue_reference); +#pragma pop_macro("DECL_ALIAS") + +template +using common_type_t = type_t>; + +// Remove top-level const+volatile+reference qualifiers from the given type. +template +using remove_cvref_t = remove_cv_t>; + +// Create a reference-to-const for the given type +template +using const_reference_t = add_lvalue_reference_t const>; + +// Workaround for CWG issue 1558. +template +struct just_void { + using type = void; +}; + +// A "do-nothing" alias template that always evaluates to void. +// +// @tparam Ts Zero or more type arguments, all discarded +template +using void_t = +#if defined(_MSC_VER) && _MSC_VER < 1910 + // Old MSVC requires that the type parameters actually be "used" to trigger SFINAE at caller. + // This was resolved by CWG issue 1558. + typename just_void::type; +#else + void; +#endif + +// Alias for integral_constant. +template +using bool_constant = std::integral_constant; + +// Holds a list of types. +// +// This template is never defined, so cannot be used in contexts that require a complete type. +template +struct mp_list; + +// Details for implementing the C++11 detection idiom. +namespace impl_detection { + +// Implementation of detection idiom for is_detected: true case +template < + // A metafunction to try and apply + template class Oper, + // The arguments to be given. These are deduced from the mp_list argument + typename... Args, + // Apply the arguments to the metafunction. If this yields a type, this function + // will be viable. If substitution fails, this function is discarded from the + // overload set. + typename SfinaeHere = Oper> +std::true_type is_detected_f(mp_list*); + +// Failure case for is_detected. Because this function takes an elipsis, this is +// less preferred than the above overload that accepts a pointer type directly. +template