Skip to content

[CXX-2625] Bring our very own string_view (plus: Some iterators + ranges backports) #1062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
71f0e61
Shorthand for trailing return type, noexcept, and single-return-state…
vector-of-bool Nov 8, 2023
f5e1d02
Some additional traits: decay_copy and rank<>
vector-of-bool Nov 8, 2023
f79efdb
New operators.hpp utilities
vector-of-bool Nov 8, 2023
ff488e3
Iterator utilities
vector-of-bool Nov 9, 2023
155f528
We don't need to start_mongod for the simple compile tasks
vector-of-bool Nov 9, 2023
e3575fa
A new set of macros for concise diagnostic controls
vector-of-bool Nov 10, 2023
fb1ac46
Disable warnings about void-dereference on Clang
vector-of-bool Nov 10, 2023
41d6765
Reorganize macro definitions
vector-of-bool Nov 13, 2023
3868e35
Fix: malformed pragmas on MSVC
vector-of-bool Nov 14, 2023
c7350d3
A small amount of std::ranges from the future
vector-of-bool Nov 14, 2023
c13e052
Bring our own std::string_view
vector-of-bool Nov 14, 2023
f2bb2fb
Avoid warnings about "unsecure stdlib" code
vector-of-bool Nov 16, 2023
fbd5535
Tweak definition of is_equality_comparable
vector-of-bool Nov 29, 2023
5740433
decay_copy is no longer needed (yet)
vector-of-bool Nov 29, 2023
b318f62
Check for MSVC's version macro
vector-of-bool Nov 29, 2023
ff7978d
No ADL-only data()
vector-of-bool Nov 29, 2023
4aeae1d
Remove c_str(), tweak "string-like" detection
vector-of-bool Nov 29, 2023
536fc05
Minor spelling and tests
vector-of-bool Nov 29, 2023
b973270
Merge branch 'master' into own-string_view.2
vector-of-bool Nov 29, 2023
39dc524
MSVC 19.10 lies about C++14 constexpr
vector-of-bool Nov 30, 2023
d67f942
Test and fixup for ADL lookup on VS 2015
vector-of-bool Nov 30, 2023
c1a7997
Cleaner size() constraint
vector-of-bool Nov 30, 2023
40f544f
unreachable_sentinel, plus support for arg swapping in equality_opera…
vector-of-bool Nov 30, 2023
e083ca5
Qualify test names in string_view tests
vector-of-bool Nov 30, 2023
43c7924
Bring our own algorithm.hpp
vector-of-bool Dec 4, 2023
09961a8
Implement find() and contains() from string_view
vector-of-bool Dec 4, 2023
e9e78ea
Merge branch 'master' into own-string_view.2
vector-of-bool Dec 4, 2023
1f3c509
Remove newer .clang-foramt option, document internal macros as internal
vector-of-bool Dec 4, 2023
67af4b3
Calm linter
vector-of-bool Dec 6, 2023
2c61f8d
Sort file lists
vector-of-bool Dec 8, 2023
7d31688
Remove string_view assertions
vector-of-bool Dec 8, 2023
bff45a1
Add/update copyright banners
vector-of-bool Dec 8, 2023
b502632
Tweak is_dereferencable to test lvalues
vector-of-bool Dec 8, 2023
347228a
Tweak some macro names/scoping
vector-of-bool Dec 8, 2023
af787d5
Updating casing on macro names
vector-of-bool Dec 8, 2023
7fb5dc3
Exclude some files from Doxygen coverage
vector-of-bool Dec 8, 2023
cb8f1d9
[foldme] macro case updates
vector-of-bool Dec 8, 2023
b89c040
Simpler iterator_concept_t
vector-of-bool Dec 8, 2023
4aad0eb
Explain the inclusion of std::contiguous_iterator_tag
vector-of-bool Dec 8, 2023
2b9291d
Update #include style
vector-of-bool Dec 8, 2023
cf495de
Qualify bsoncxx::detail references
vector-of-bool Dec 8, 2023
c7168a5
Spelling/wording tweaks
vector-of-bool Dec 11, 2023
f59fbea
Remove C++20+ string-view APIs
vector-of-bool Dec 11, 2023
348fa3e
More testing and fixes for fencepost errors in string searches
vector-of-bool Dec 11, 2023
b5398c1
Drop range constructs. Test+fix some more edge cases in string search…
vector-of-bool Dec 12, 2023
2a06503
Drop equality requirement
vector-of-bool Dec 12, 2023
c948aa6
Merge branch 'master' into own-string_view.2
vector-of-bool Dec 14, 2023
ffc332e
More review and cleanup + spec matching
vector-of-bool Dec 14, 2023
3608164
More careful conversion to/from std types
vector-of-bool Dec 14, 2023
87bc426
ClangFormat changes its mind in the future, +stray noexcepts
vector-of-bool Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .mci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ tasks:
- name: compile_with_shared_libs
commands:
- func: "setup"
- func: "start_mongod"
- func: "fetch_c_driver_source"
- func: "compile"

Expand Down
3 changes: 2 additions & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE =
EXCLUDE = src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/stdx/operators.hpp \
src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/stdx/type_traits.hpp

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down
2 changes: 2 additions & 0 deletions src/bsoncxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ set_dist_list(src_bsoncxx_include_DIST
bsoncxx/v_noabi/bsoncxx/config/compiler.hpp
bsoncxx/v_noabi/bsoncxx/config/postlude.hpp
bsoncxx/v_noabi/bsoncxx/config/prelude.hpp
bsoncxx/v_noabi/bsoncxx/config/util.hpp
bsoncxx/v_noabi/bsoncxx/decimal128-fwd.hpp
bsoncxx/v_noabi/bsoncxx/decimal128.hpp
bsoncxx/v_noabi/bsoncxx/document/element-fwd.hpp
Expand All @@ -83,6 +84,7 @@ set_dist_list(src_bsoncxx_include_DIST
bsoncxx/v_noabi/bsoncxx/oid-fwd.hpp
bsoncxx/v_noabi/bsoncxx/oid.hpp
bsoncxx/v_noabi/bsoncxx/stdx/make_unique.hpp
bsoncxx/v_noabi/bsoncxx/stdx/operators.hpp
bsoncxx/v_noabi/bsoncxx/stdx/optional.hpp
bsoncxx/v_noabi/bsoncxx/stdx/string_view.hpp
bsoncxx/v_noabi/bsoncxx/stdx/type_traits.hpp
Expand Down
40 changes: 27 additions & 13 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,35 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if defined(_MSC_VER)
// clang-format off

#define BSONCXX_IF_MSVC(...)
#define BSONCXX_IF_GCC(...)
#define BSONCXX_IF_CLANG(...)
#define BSONCXX_IF_GNU_LIKE(...) \
BSONCXX_IF_GCC(__VA_ARGS__) \
BSONCXX_IF_CLANG(__VA_ARGS__)

#ifdef __GNUC__
#ifdef __clang__
#undef BSONCXX_IF_CLANG
#define BSONCXX_IF_CLANG(...) __VA_ARGS__
#else
#undef BSONCXX_IF_GCC
#define BSONCXX_IF_GCC(...) __VA_ARGS__
#endif
#elif defined(_MSC_VER)
#undef BSONCXX_IF_MSVC
#define BSONCXX_IF_MSVC(...) __VA_ARGS__
#endif

// clang-format on

// Disable MSVC warnings that cause a lot of noise related to DLL visibility
// for types that we don't control (like std::unique_ptr).
#pragma warning(push)
#pragma warning(disable : 4251 4275)
BSONCXX_PUSH_WARNINGS();
BSONCXX_DISABLE_WARNING(MSVC(4251));
BSONCXX_DISABLE_WARNING(MSVC(5275));

#define BSONCXX_INLINE inline BSONCXX_PRIVATE

#define BSONCXX_CALL __cdecl

#else

#define BSONCXX_INLINE inline BSONCXX_PRIVATE

#define BSONCXX_CALL

#endif
#define BSONCXX_CALL BSONCXX_IF_MSVC(__cdecl)
31 changes: 28 additions & 3 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/postlude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
// compiler.hpp
#undef BSONCXX_INLINE
#pragma pop_macro("BSONCXX_INLINE")
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
BSONCXX_POP_WARNINGS();
#undef BSONCXX_CALL
#pragma pop_macro("BSONCXX_CALL")

Expand Down Expand Up @@ -67,8 +65,35 @@
#undef BSONCXX_UNREACHABLE
#pragma pop_macro("BSONCXX_UNREACHABLE")

#pragma pop_macro("bsoncxx_cxx14_constexpr")
#pragma pop_macro("BSONCXX_RETURNS")

// CXX-2769: out-of-place, but remains for backward compatibility.
#ifdef BSONCXX_ENUM
static_assert(false, "BSONCXX_ENUM must be undef'ed");
#endif
#pragma pop_macro("BSONCXX_ENUM")

// util.hpp
#pragma pop_macro("BSONCXX_PUSH_WARNINGS")
#pragma pop_macro("BSONCXX_POP_WARNINGS")
#pragma pop_macro("BSONCXX_DISABLE_WARNING")

#pragma pop_macro("_bsoncxxDisableWarningImpl_for_MSVC")
#pragma pop_macro("_bsoncxxDisableWarningImpl_for_GCC")
#pragma pop_macro("_bsoncxxDisableWarningImpl_for_GNU")
#pragma pop_macro("_bsoncxxDisableWarningImpl_for_Clang")

#pragma pop_macro("BSONCXX_CONCAT")
#pragma pop_macro("BSONCXX_CONCAT_IMPL")

#pragma pop_macro("BSONCXX_PRAGMA")
#pragma pop_macro("_bsoncxxPragma")
#pragma pop_macro("BSONCXX_STRINGIFY_IMPL")
#pragma pop_macro("BSONCXX_STRINGIFY")
#pragma pop_macro("BSONCXX_FORCE_SEMICOLON")

#pragma pop_macro("BSONCXX_IF_MSVC")
#pragma pop_macro("BSONCXX_IF_GCC")
#pragma pop_macro("BSONCXX_IF_CLANG")
#pragma pop_macro("BSONCXX_IF_GNU_LIKE")
44 changes: 44 additions & 0 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/prelude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,53 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// util.hpp
#pragma push_macro("BSONCXX_CONCAT")
#undef BSONCXX_CONCAT
#pragma push_macro("BSONCXX_CONCAT_IMPL")
#undef BSONCXX_CONCAT_IMPL
#pragma push_macro("BSONCXX_STRINGIFY")
#undef BSONCXX_STRINGIFY
#pragma push_macro("BSONCXX_STRINGIFY_IMPL")
#undef BSONCXX_STRINGIFY_IMPL
#pragma push_macro("BSONCXX_PRAGMA")
#undef BSONCXX_PRAGMA
#pragma push_macro("_bsoncxxPragma")
#undef _bsoncxxPragma
#pragma push_macro("BSONCXX_FORCE_SEMICOLON")
#undef BSONCXX_FORCE_SEMICOLON
#pragma push_macro("BSONCXX_RETURNS")
#undef BSONCXX_RETURNS
#pragma push_macro("bsoncxx_cxx14_constexpr")
#undef bsoncxx_cxx14_constexpr
#pragma push_macro("BSONCXX_DISABLE_WARNING")
#undef BSONCXX_DISABLE_WARNING
#pragma push_macro("BSONCXX_PUSH_WARNINGS")
#undef BSONCXX_PUSH_WARNINGS
#pragma push_macro("BSONCXX_POP_WARNINGS")
#undef BSONCXX_POP_WARNINGS
#pragma push_macro("_bsoncxxDisableWarningImpl_for_GCC")
#undef _bsoncxxDisableWarningImpl_for_GCC
#pragma push_macro("_bsoncxxDisableWarningImpl_for_Clang")
#undef _bsoncxxDisableWarningImpl_for_Clang
#pragma push_macro("_bsoncxxDisableWarningImpl_for_MSVC")
#undef _bsoncxxDisableWarningImpl_for_MSVC
#pragma push_macro("_bsoncxxDisableWarningImpl_for_GNU")
#undef _bsoncxxDisableWarningImpl_for_GNU

// compiler.hpp
#pragma push_macro("BSONCXX_INLINE")
#undef BSONCXX_INLINE
#pragma push_macro("BSONCXX_CALL")
#undef BSONCXX_CALL
#pragma push_macro("BSONCXX_IF_MSVC")
#undef BSONCXX_IF_MSVC
#pragma push_macro("BSONCXX_IF_GCC")
#undef BSONCXX_IF_GCC
#pragma push_macro("BSONCXX_IF_CLANG")
#undef BSONCXX_IF_CLANG
#pragma push_macro("BSONCXX_IF_GNU_LIKE")
#undef BSONCXX_IF_GNU_LIKE

// config.hpp (generated by CMake)
#pragma push_macro("BSONCXX_INLINE_NAMESPACE_BEGIN")
Expand Down Expand Up @@ -60,6 +102,8 @@
#pragma push_macro("BSONCXX_NO_DEPRECATED")
#undef BSONCXX_NO_DEPRECATED

#include <bsoncxx/config/util.hpp>
//
#include <bsoncxx/config/compiler.hpp>
#include <bsoncxx/config/config.hpp>
#include <bsoncxx/config/export.hpp>
Expand Down
133 changes: 133 additions & 0 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// clang-format off
/**
* @internal
* @brief Convert the given macro argument to a string literal, after macro expansion
*/
#define BSONCXX_STRINGIFY(...) BSONCXX_STRINGIFY_IMPL(__VA_ARGS__)
#define BSONCXX_STRINGIFY_IMPL(...) #__VA_ARGS__

/**
* @brief Token-paste two macro arguments, after macro expansion
*/
#define BSONCXX_CONCAT(A, ...) BSONCXX_CONCAT_IMPL(A, __VA_ARGS__)
#define BSONCXX_CONCAT_IMPL(A, ...) A##__VA_ARGS__

/**
* @internal
* @brief 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_PRAGMA(GCC diagnostic ignore "-Wconversion")
*
* will become:
*
* _Pragma("GCC diagnostic ignore \"-Wconversion\"")
*
*/
#define BSONCXX_PRAGMA(...) _bsoncxxPragma(__VA_ARGS__)
#ifdef _MSC_VER
// Old MSVC doesn't recognize C++11 _Pragma(), but it always recognized __pragma
#define _bsoncxxPragma(...) __pragma(__VA_ARGS__)
#else
#define _bsoncxxPragma(...) _Pragma(BSONCXX_STRINGIFY(__VA_ARGS__))
#endif

/**
* @internal
* @brief 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_FORCE_SEMICOLON static_assert(true, "")

/**
* @internal
* @brief Add a trailing noexcept, decltype-return, and return-body to a
* function definition. (Not compatible with lambda expressions.)
*
* Example:
*
* template <typename T>
* auto foo(T x, T y) BSONCXX_RETURNS(x + y);
*
* Becomes:
*
* template <typename T>
* auto foo(T x, T y) noexcept(noexcept(x + y))
* -> decltype(x + y)
* { return x + y };
*
*/
#define BSONCXX_RETURNS(...) \
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { \
return __VA_ARGS__; \
} \
BSONCXX_FORCE_SEMICOLON

/**
* @internal
* @macro mongocxx_cxx14_constexpr
* @brief 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_cxx14_constexpr constexpr
#else
#define bsoncxx_cxx14_constexpr inline
#endif

/**
* @internal
* @brief Disable a warning for a particular compiler.
*
* The argument should be of the form:
*
* - Clang(<flag-string-literal>)
* - GCC(<flag-string-literal>)
* - GNU(<flag-string-literal>)
* - MSVC(<id-integer-literal>)
*
* The "GNU" form applies to both GCC and Clang
*/
#define BSONCXX_DISABLE_WARNING(Spec) \
BSONCXX_CONCAT(_bsoncxxDisableWarningImpl_for_, Spec) \
BSONCXX_FORCE_SEMICOLON

/**
* @internal
* @brief Push the current compiler diagnostics settings state
*/
#define BSONCXX_PUSH_WARNINGS() \
BSONCXX_IF_GNU_LIKE(BSONCXX_PRAGMA(GCC diagnostic push)) \
BSONCXX_IF_MSVC(BSONCXX_PRAGMA(warning(push))) \
BSONCXX_FORCE_SEMICOLON

/**
* @internal
* @brief Restore prior compiler diagnostics settings from before the most
* recent BSONCXX_PUSH_WARNINGS()
*/
#define BSONCXX_POP_WARNINGS() \
BSONCXX_IF_GNU_LIKE(BSONCXX_PRAGMA(GCC diagnostic pop)) \
BSONCXX_IF_MSVC(BSONCXX_PRAGMA(warning(pop))) \
BSONCXX_FORCE_SEMICOLON

#define _bsoncxxDisableWarningImpl_for_GCC(...) \
BSONCXX_IF_GCC(BSONCXX_PRAGMA(GCC diagnostic ignored __VA_ARGS__))

#define _bsoncxxDisableWarningImpl_for_Clang(...) \
BSONCXX_IF_CLANG(BSONCXX_PRAGMA(GCC diagnostic ignored __VA_ARGS__))

#define _bsoncxxDisableWarningImpl_for_GNU(...) \
_bsoncxxDisableWarningImpl_for_GCC(__VA_ARGS__) \
_bsoncxxDisableWarningImpl_for_Clang(__VA_ARGS__)

#define _bsoncxxDisableWarningImpl_for_MSVC(...) \
BSONCXX_IF_MSVC(BSONCXX_PRAGMA(warning(disable : __VA_ARGS__)))
12 changes: 4 additions & 8 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/document/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,13 @@ class value {
std::size_t _length{0};
};

#if !defined(__clang__) && defined(__GNUC__) && (__cplusplus >= 201709L)
// Silence false positive with g++ 10.2.1 on Debian 11.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
BSONCXX_INLINE document::view value::view() const noexcept {
// Silence false positive with g++ 10.2.1 on Debian 11.
BSONCXX_PUSH_WARNINGS();
BSONCXX_DISABLE_WARNING(GCC("-Wmaybe-uninitialized"));
return document::view{static_cast<uint8_t*>(_data.get()), _length};
BSONCXX_POP_WARNINGS();
}
#if !defined(__clang__) && defined(__GNUC__) && (__cplusplus >= 201709L)
#pragma GCC diagnostic pop
#endif

BSONCXX_INLINE value::operator document::view() const noexcept {
return view();
Expand Down
Loading