Skip to content

Commit 86d4a2b

Browse files
authored
CXX-2790 Redeclare bsoncxx::v_noabi as a non-inline namespace (#1066)
* Remove reference to ABI namespace in examples * Refactor bsoncxx::v_noabi as a non-inline namespace * Add using-declarations to redeclare entities in root namespace * Update CONTRIBUTING with root namespace qualifier guidelines
1 parent 198894a commit 86d4a2b

File tree

110 files changed

+1201
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1201
-585
lines changed

CONTRIBUTING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,50 @@ inline namespace v_noabi {
8787
#include <driver/config/postlude.hpp>
8888
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8989

90+
### Library Root Namespace
91+
92+
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.
93+
94+
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.
95+
96+
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:
97+
98+
```cpp
99+
namespace mongocxx {
100+
namespace v_noabi {
101+
namespace example {
102+
103+
struct type {}; // The type intended to be referenced below.
104+
105+
// Problem: when `mongocxx::example::type` is changed from `v_noabi` to `v1`,
106+
// this parameter type will also (incorrectly) change from `v_noabi` to `v1`.
107+
void fn(mongocxx::example::type param);
108+
109+
} // namespace example
110+
} // namespace v_noabi
111+
} // namespace mongocxx
112+
```
113+
114+
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:
115+
116+
```cpp
117+
namespace mongocxx {
118+
namespace v_noabi {
119+
namespace example {
120+
121+
struct type {}; // The type intended to be referenced below.
122+
123+
// OK: always resolves to `mongocxx::v_noabi::example::type`.
124+
void fn(type param);
125+
126+
// Also OK: unambiguously refers to the ABI-specific type.
127+
void fn(mongocxx::v_noabi::example::type param);
128+
129+
} // namespace example
130+
} // namespace v_noabi
131+
} // namespace mongocxx
132+
```
133+
90134
### Class Declarations
91135

92136
Guidelines:

examples/mongocxx/mongodb.com/documentation_examples.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ static void snapshot_example2(mongocxx::client& client) {
14671467
}
14681468
}
14691469

1470-
static bool version_at_least(mongocxx::v_noabi::database& db, int minimum_major) {
1470+
static bool version_at_least(mongocxx::database& db, int minimum_major) {
14711471
using bsoncxx::builder::basic::kvp;
14721472
using bsoncxx::builder::basic::make_document;
14731473

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/element-fwd.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <bsoncxx/config/prelude.hpp>
1818

1919
namespace bsoncxx {
20-
inline namespace v_noabi {
20+
namespace v_noabi {
2121
namespace array {
2222

2323
class BSONCXX_API element;
@@ -26,4 +26,12 @@ class BSONCXX_API element;
2626
} // namespace v_noabi
2727
} // namespace bsoncxx
2828

29+
namespace bsoncxx {
30+
namespace array {
31+
32+
using ::bsoncxx::v_noabi::array::element;
33+
34+
} // namespace array
35+
} // namespace bsoncxx
36+
2937
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/element.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <bsoncxx/config/prelude.hpp>
2727

2828
namespace bsoncxx {
29-
inline namespace v_noabi {
29+
namespace v_noabi {
3030
namespace array {
3131

3232
///
@@ -122,4 +122,13 @@ BSONCXX_API bool BSONCXX_CALL operator!=(const types::bson_value::view& v, const
122122
} // namespace v_noabi
123123
} // namespace bsoncxx
124124

125+
namespace bsoncxx {
126+
namespace array {
127+
128+
using ::bsoncxx::v_noabi::array::operator==;
129+
using ::bsoncxx::v_noabi::array::operator!=;
130+
131+
} // namespace array
132+
} // namespace bsoncxx
133+
125134
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/value-fwd.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <bsoncxx/config/prelude.hpp>
1818

1919
namespace bsoncxx {
20-
inline namespace v_noabi {
20+
namespace v_noabi {
2121
namespace array {
2222

2323
class BSONCXX_API value;
@@ -26,4 +26,12 @@ class BSONCXX_API value;
2626
} // namespace v_noabi
2727
} // namespace bsoncxx
2828

29+
namespace bsoncxx {
30+
namespace array {
31+
32+
using ::bsoncxx::v_noabi::array::value;
33+
34+
} // namespace array
35+
} // namespace bsoncxx
36+
2937
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/value.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <bsoncxx/config/prelude.hpp>
2626

2727
namespace bsoncxx {
28-
inline namespace v_noabi {
28+
namespace v_noabi {
2929
namespace array {
3030

3131
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/view-fwd.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <bsoncxx/config/prelude.hpp>
1818

1919
namespace bsoncxx {
20-
inline namespace v_noabi {
20+
namespace v_noabi {
2121
namespace array {
2222

2323
class BSONCXX_API view;
@@ -26,4 +26,12 @@ class BSONCXX_API view;
2626
} // namespace v_noabi
2727
} // namespace bsoncxx
2828

29+
namespace bsoncxx {
30+
namespace array {
31+
32+
using ::bsoncxx::v_noabi::array::view;
33+
34+
} // namespace array
35+
} // namespace bsoncxx
36+
2937
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/view.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <bsoncxx/config/prelude.hpp>
2828

2929
namespace bsoncxx {
30-
inline namespace v_noabi {
30+
namespace v_noabi {
3131
namespace array {
3232

3333
///

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/view_or_value.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@
2222
#include <bsoncxx/config/prelude.hpp>
2323

2424
namespace bsoncxx {
25-
inline namespace v_noabi {
25+
namespace v_noabi {
2626
namespace array {
2727

28-
using view_or_value = bsoncxx::view_or_value<array::view, array::value>;
28+
using view_or_value = ::bsoncxx::v_noabi::view_or_value<view, value>;
2929

3030
} // namespace array
3131
} // namespace v_noabi
3232
} // namespace bsoncxx
3333

34+
namespace bsoncxx {
35+
namespace array {
36+
37+
using ::bsoncxx::v_noabi::array::view_or_value;
38+
39+
} // namespace array
40+
} // namespace bsoncxx
41+
3442
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/builder/basic/array-fwd.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#pragma once
1616

1717
namespace bsoncxx {
18-
inline namespace v_noabi {
18+
namespace v_noabi {
1919
namespace builder {
2020
namespace basic {
2121

@@ -25,3 +25,13 @@ class array;
2525
} // namespace builder
2626
} // namespace v_noabi
2727
} // namespace bsoncxx
28+
29+
namespace bsoncxx {
30+
namespace builder {
31+
namespace basic {
32+
33+
using ::bsoncxx::v_noabi::builder::basic::array;
34+
35+
} // namespace basic
36+
} // namespace builder
37+
} // namespace bsoncxx

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/builder/basic/array.hpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <bsoncxx/config/prelude.hpp>
2727

2828
namespace bsoncxx {
29-
inline namespace v_noabi {
29+
namespace v_noabi {
3030
namespace builder {
3131
namespace basic {
3232

@@ -57,7 +57,7 @@ class array : public sub_array {
5757
///
5858
/// @return A view of the BSON array.
5959
///
60-
BSONCXX_INLINE bsoncxx::array::view view() const {
60+
BSONCXX_INLINE bsoncxx::v_noabi::array::view view() const {
6161
return _core.view_array();
6262
}
6363

@@ -67,7 +67,7 @@ class array : public sub_array {
6767
///
6868
/// @return A view of the current builder contents.
6969
///
70-
BSONCXX_INLINE operator bsoncxx::array::view() const {
70+
BSONCXX_INLINE operator bsoncxx::v_noabi::array::view() const {
7171
return view();
7272
}
7373

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

@@ -103,13 +103,12 @@ class array : public sub_array {
103103
/// builder::basic::sub_array::append accepts.
104104
///
105105
/// @return
106-
/// A bsoncxx::array::value containing the elements.
106+
/// A bsoncxx::v_noabi::array::value containing the elements.
107107
///
108108
template <typename... Args>
109-
bsoncxx::array::value BSONCXX_CALL make_array(Args&&... args) {
110-
basic::array array;
109+
bsoncxx::v_noabi::array::value BSONCXX_CALL make_array(Args&&... args) {
110+
array array;
111111
array.append(std::forward<Args>(args)...);
112-
113112
return array.extract();
114113
}
115114

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

120+
namespace bsoncxx {
121+
namespace builder {
122+
namespace basic {
123+
124+
using ::bsoncxx::v_noabi::builder::basic::make_array;
125+
126+
} // namespace basic
127+
} // namespace builder
128+
} // namespace bsoncxx
129+
121130
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/builder/basic/document-fwd.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#pragma once
1616

1717
namespace bsoncxx {
18-
inline namespace v_noabi {
18+
namespace v_noabi {
1919
namespace builder {
2020
namespace basic {
2121

@@ -25,3 +25,13 @@ class document;
2525
} // namespace builder
2626
} // namespace v_noabi
2727
} // namespace bsoncxx
28+
29+
namespace bsoncxx {
30+
namespace builder {
31+
namespace basic {
32+
33+
using ::bsoncxx::v_noabi::builder::basic::document;
34+
35+
} // namespace basic
36+
} // namespace builder
37+
} // namespace bsoncxx

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/builder/basic/document.hpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <bsoncxx/config/prelude.hpp>
2828

2929
namespace bsoncxx {
30-
inline namespace v_noabi {
30+
namespace v_noabi {
3131
namespace builder {
3232
namespace basic {
3333

@@ -59,7 +59,7 @@ class document : public sub_document {
5959
///
6060
/// @return A view of the BSON document.
6161
///
62-
BSONCXX_INLINE bsoncxx::document::view view() const {
62+
BSONCXX_INLINE bsoncxx::v_noabi::document::view view() const {
6363
return _core.view_document();
6464
}
6565

@@ -69,7 +69,7 @@ class document : public sub_document {
6969
///
7070
/// @return A view of the current builder contents.
7171
///
72-
BSONCXX_INLINE operator bsoncxx::document::view() const {
72+
BSONCXX_INLINE operator bsoncxx::v_noabi::document::view() const {
7373
return view();
7474
}
7575

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

@@ -105,13 +105,12 @@ class document : public sub_document {
105105
/// builder::basic::sub_document::append accepts.
106106
///
107107
/// @return
108-
/// A bsoncxx::document::value containing the elements.
108+
/// A bsoncxx::v_noabi::document::value containing the elements.
109109
///
110110
template <typename... Args>
111-
bsoncxx::document::value BSONCXX_CALL make_document(Args&&... args) {
112-
basic::document document;
111+
bsoncxx::v_noabi::document::value BSONCXX_CALL make_document(Args&&... args) {
112+
document document;
113113
document.append(std::forward<Args>(args)...);
114-
115114
return document.extract();
116115
}
117116

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

122+
namespace bsoncxx {
123+
namespace builder {
124+
namespace basic {
125+
126+
using ::bsoncxx::v_noabi::builder::basic::make_document;
127+
128+
} // namespace basic
129+
} // namespace builder
130+
} // namespace bsoncxx
131+
123132
#include <bsoncxx/config/postlude.hpp>

0 commit comments

Comments
 (0)