Skip to content

CXX-2790 Redeclare bsoncxx::v_noabi as a non-inline namespace #1066

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 32 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f0ee875
Remove reference to ABI namespace in examples
eramongodb Dec 4, 2023
bf142f6
Rename bsoncxx::v_noabi to bsoncxx::wip
eramongodb Dec 4, 2023
b7d0ca8
bsoncxx::stdx
eramongodb Dec 4, 2023
b44d551
bsoncxx type traits
eramongodb Dec 4, 2023
bb73b53
bsoncxx::view_or_value
eramongodb Dec 4, 2023
8a0e0fd
bsoncxx::types
eramongodb Dec 4, 2023
a7d7841
bsoncxx::types::bson_value::value
eramongodb Dec 4, 2023
9bd8440
bsoncxx::types::bson_value::make_value
eramongodb Dec 4, 2023
14475bc
bsoncxx::types::bson_value::view
eramongodb Dec 4, 2023
6060cb8
bsoncxx::types::bson_value::view_or_value
eramongodb Dec 4, 2023
2a5bfcd
bsoncxx::types::value
eramongodb Dec 4, 2023
6167f30
bsoncxx::string::to_string
eramongodb Dec 4, 2023
a2ac2ce
bsoncxx::string::view_or_value
eramongodb Dec 4, 2023
7cae750
bsoncxx::array::element
eramongodb Dec 4, 2023
9fe4617
bsoncxx::array::value
eramongodb Dec 4, 2023
0868f27
bsoncxx::array::view
eramongodb Dec 4, 2023
2cd794f
bsoncxx::array::view_or_value
eramongodb Dec 4, 2023
0fc7a72
bsoncxx::document::element
eramongodb Dec 4, 2023
0cbe33a
bsoncxx::document::value
eramongodb Dec 4, 2023
2d1a8d9
bsoncxx::document::view
eramongodb Dec 4, 2023
1a9fe0e
bsoncxx::document::view_or_value
eramongodb Dec 4, 2023
759665c
bsoncxx::decimal128
eramongodb Dec 4, 2023
a1c7a85
bsoncxx::oid
eramongodb Dec 4, 2023
517a4f8
bsoncxx::builder
eramongodb Dec 4, 2023
2a322a9
bsoncxx::exception
eramongodb Dec 4, 2023
13f2179
bsoncxx::error_code
eramongodb Dec 4, 2023
9234779
bsoncxx::(to|from)_json
eramongodb Dec 4, 2023
3568088
bsoncxx::validate
eramongodb Dec 4, 2023
aca83de
bsoncxx::util::is_functor
eramongodb Dec 4, 2023
237de8d
bsoncxx non-public entities
eramongodb Dec 4, 2023
4a406a6
Update CONTRIBUTING with root namespace qualifier guidelines
eramongodb Dec 11, 2023
753bdb9
Remove unnecessary ABI namespace qualifier for string_view
eramongodb Dec 11, 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
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,50 @@ inline namespace v_noabi {
#include <driver/config/postlude.hpp>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### Library Root Namespace

The library root namespace declares ABI namespaces (e.g. `mongocxx::v_noabi`, `mongocxx::v1`, etc.), within which symbols are declared according to their compatibility with an ABI version.

The library root namespace also redeclares ABI-specific entities without an ABI namespace qualifier (e.g. `mongocxx::v_noabi::document::view` as `mongocxx::document::view`) to allow users to automatically opt-into the latest supported ABI version of a given entity without requiring changes to source code. The root namespace redeclarations are intended to be the default method for using library entities. A user should only include the ABI namespace in a qualifier if they require compatibility with that specific ABI version.

To avoid being affected by changes to root namespace redeclarations, interfaces declared within an ABI namespace must not be written in terms of a root namespace redeclaration:

```cpp
namespace mongocxx {
namespace v_noabi {
namespace example {

struct type {}; // The type intended to be referenced below.

// Problem: when `mongocxx::example::type` is changed from `v_noabi` to `v1`,
// this parameter type will also (incorrectly) change from `v_noabi` to `v1`.
void fn(mongocxx::example::type param);

} // namespace example
} // namespace v_noabi
} // namespace mongocxx
```

References to ABI-specific entities in ABI namespaces must always be (un)qualified such that it is not affected by changes to root namespace redeclarations:

```cpp
namespace mongocxx {
namespace v_noabi {
namespace example {

struct type {}; // The type intended to be referenced below.

// OK: always resolves to `mongocxx::v_noabi::example::type`.
void fn(type param);

// Also OK: unambiguously refers to the ABI-specific type.
void fn(mongocxx::v_noabi::example::type param);

} // namespace example
} // namespace v_noabi
} // namespace mongocxx
```

### Class Declarations

Guidelines:
Expand Down
2 changes: 1 addition & 1 deletion examples/mongocxx/mongodb.com/documentation_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ static void snapshot_example2(mongocxx::client& client) {
}
}

static bool version_at_least(mongocxx::v_noabi::database& db, int minimum_major) {
static bool version_at_least(mongocxx::database& db, int minimum_major) {
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace array {

class BSONCXX_API element;
Expand All @@ -26,4 +26,12 @@ class BSONCXX_API element;
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace array {

using ::bsoncxx::v_noabi::array::element;

} // namespace array
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
11 changes: 10 additions & 1 deletion src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace array {

///
Expand Down Expand Up @@ -122,4 +122,13 @@ BSONCXX_API bool BSONCXX_CALL operator!=(const types::bson_value::view& v, const
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace array {

using ::bsoncxx::v_noabi::array::operator==;
using ::bsoncxx::v_noabi::array::operator!=;

} // namespace array
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace array {

class BSONCXX_API value;
Expand All @@ -26,4 +26,12 @@ class BSONCXX_API value;
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace array {

using ::bsoncxx::v_noabi::array::value;

} // namespace array
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace array {

///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace array {

class BSONCXX_API view;
Expand All @@ -26,4 +26,12 @@ class BSONCXX_API view;
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace array {

using ::bsoncxx::v_noabi::array::view;

} // namespace array
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace array {

///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace array {

using view_or_value = bsoncxx::view_or_value<array::view, array::value>;
using view_or_value = ::bsoncxx::v_noabi::view_or_value<view, value>;

} // namespace array
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace array {

using ::bsoncxx::v_noabi::array::view_or_value;

} // namespace array
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#pragma once

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace builder {
namespace basic {

Expand All @@ -25,3 +25,13 @@ class array;
} // namespace builder
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace builder {
namespace basic {

using ::bsoncxx::v_noabi::builder::basic::array;

} // namespace basic
} // namespace builder
} // namespace bsoncxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace builder {
namespace basic {

Expand Down Expand Up @@ -57,7 +57,7 @@ class array : public sub_array {
///
/// @return A view of the BSON array.
///
BSONCXX_INLINE bsoncxx::array::view view() const {
BSONCXX_INLINE bsoncxx::v_noabi::array::view view() const {
return _core.view_array();
}

Expand All @@ -67,7 +67,7 @@ class array : public sub_array {
///
/// @return A view of the current builder contents.
///
BSONCXX_INLINE operator bsoncxx::array::view() const {
BSONCXX_INLINE operator bsoncxx::v_noabi::array::view() const {
return view();
}

Expand All @@ -80,7 +80,7 @@ class array : public sub_array {
/// After calling extract() it is illegal to call any methods
/// on this class, unless it is subsequenly moved into.
///
BSONCXX_INLINE bsoncxx::array::value extract() {
BSONCXX_INLINE bsoncxx::v_noabi::array::value extract() {
return _core.extract_array();
}

Expand All @@ -103,13 +103,12 @@ class array : public sub_array {
/// builder::basic::sub_array::append accepts.
///
/// @return
/// A bsoncxx::array::value containing the elements.
/// A bsoncxx::v_noabi::array::value containing the elements.
///
template <typename... Args>
bsoncxx::array::value BSONCXX_CALL make_array(Args&&... args) {
basic::array array;
bsoncxx::v_noabi::array::value BSONCXX_CALL make_array(Args&&... args) {
array array;
array.append(std::forward<Args>(args)...);

return array.extract();
}

Expand All @@ -118,4 +117,14 @@ bsoncxx::array::value BSONCXX_CALL make_array(Args&&... args) {
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace builder {
namespace basic {

using ::bsoncxx::v_noabi::builder::basic::make_array;

} // namespace basic
} // namespace builder
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#pragma once

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace builder {
namespace basic {

Expand All @@ -25,3 +25,13 @@ class document;
} // namespace builder
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace builder {
namespace basic {

using ::bsoncxx::v_noabi::builder::basic::document;

} // namespace basic
} // namespace builder
} // namespace bsoncxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
inline namespace v_noabi {
namespace v_noabi {
namespace builder {
namespace basic {

Expand Down Expand Up @@ -59,7 +59,7 @@ class document : public sub_document {
///
/// @return A view of the BSON document.
///
BSONCXX_INLINE bsoncxx::document::view view() const {
BSONCXX_INLINE bsoncxx::v_noabi::document::view view() const {
return _core.view_document();
}

Expand All @@ -69,7 +69,7 @@ class document : public sub_document {
///
/// @return A view of the current builder contents.
///
BSONCXX_INLINE operator bsoncxx::document::view() const {
BSONCXX_INLINE operator bsoncxx::v_noabi::document::view() const {
return view();
}

Expand All @@ -82,7 +82,7 @@ class document : public sub_document {
/// After calling extract() it is illegal to call any methods
/// on this class, unless it is subsequently moved into.
///
BSONCXX_INLINE bsoncxx::document::value extract() {
BSONCXX_INLINE bsoncxx::v_noabi::document::value extract() {
return _core.extract_document();
}

Expand All @@ -105,13 +105,12 @@ class document : public sub_document {
/// builder::basic::sub_document::append accepts.
///
/// @return
/// A bsoncxx::document::value containing the elements.
/// A bsoncxx::v_noabi::document::value containing the elements.
///
template <typename... Args>
bsoncxx::document::value BSONCXX_CALL make_document(Args&&... args) {
basic::document document;
bsoncxx::v_noabi::document::value BSONCXX_CALL make_document(Args&&... args) {
document document;
document.append(std::forward<Args>(args)...);

return document.extract();
}

Expand All @@ -120,4 +119,14 @@ bsoncxx::document::value BSONCXX_CALL make_document(Args&&... args) {
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace builder {
namespace basic {

using ::bsoncxx::v_noabi::builder::basic::make_document;

} // namespace basic
} // namespace builder
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
Loading