Skip to content

Commit 71f0e61

Browse files
Shorthand for trailing return type, noexcept, and single-return-statement
1 parent 8c81c21 commit 71f0e61

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/postlude.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
#undef BSONCXX_UNREACHABLE
6868
#pragma pop_macro("BSONCXX_UNREACHABLE")
6969

70+
#pragma pop_macro("mongo_cxx14_constexpr")
71+
#pragma pop_macro("bsoncxx_returns")
72+
7073
// CXX-2769: out-of-place, but remains for backward compatibility.
7174
#ifdef BSONCXX_ENUM
7275
static_assert(false, "BSONCXX_ENUM must be undef'ed");

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/prelude.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,20 @@
9090
/// @namespace bsoncxx::v_noabi::stdx
9191
/// Declares polyfills for C++17 forward compatibility.
9292
///
93+
94+
#pragma push_macro("mongo_cxx14_constexpr")
95+
#if __cplusplus >= 201402L
96+
#define mongo_cxx14_constexpr constexpr
97+
#else
98+
#define mongo_cxx14_constexpr inline
99+
#endif
100+
101+
#pragma push_macro("bsoncxx_returns")
102+
/**
103+
* @brief Add a trailing noexcept, decltype-return, and return-body to a function definition.
104+
*/
105+
#define bsoncxx_returns(...) \
106+
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { \
107+
return __VA_ARGS__; \
108+
} \
109+
static_assert(true, "")

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/stdx/type_traits.hpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -344,31 +344,25 @@ using requires_not_t = requires_t<Type, negation<disjunction<Traits...>>>;
344344
// Impl: invoke/is_invocable
345345
namespace impl_invoke {
346346

347-
#pragma push_macro("RETURNS")
348-
#define RETURNS(...) \
349-
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { \
350-
return __VA_ARGS__; \
351-
} \
352-
static_assert(true, "")
353-
354347
template <bool IsMemberObject, bool IsMemberFunction>
355348
struct invoker {
356349
template <typename F, typename... Args>
357350
constexpr static auto apply(F&& fun, Args&&... args)
358-
RETURNS(static_cast<F&&>(fun)(static_cast<Args&&>(args)...));
351+
bsoncxx_returns(static_cast<F&&>(fun)(static_cast<Args&&>(args)...));
359352
};
360353

361354
template <>
362355
struct invoker<false, true> {
363356
template <typename F, typename Self, typename... Args>
364357
constexpr static auto apply(F&& fun, Self&& self, Args&&... args)
365-
RETURNS((static_cast<Self&&>(self).*fun)(static_cast<Args&&>(args)...));
358+
bsoncxx_returns((static_cast<Self&&>(self).*fun)(static_cast<Args&&>(args)...));
366359
};
367360

368361
template <>
369362
struct invoker<true, false> {
370363
template <typename F, typename Self>
371-
constexpr static auto apply(F&& fun, Self&& self) RETURNS(static_cast<Self&&>(self).*fun);
364+
constexpr static auto apply(F&& fun, Self&& self)
365+
bsoncxx_returns(static_cast<Self&&>(self).*fun);
372366
};
373367

374368
} // namespace impl_invoke
@@ -383,13 +377,11 @@ static constexpr struct invoke_fn {
383377

384378
template <typename F, typename... Args, typename Fd = remove_cvref_t<F>>
385379
constexpr auto operator()(F&& fn, Args&&... args) const
386-
RETURNS(impl_invoke::invoker<std::is_member_object_pointer<Fd>::value,
387-
std::is_member_function_pointer<Fd>::value> //
388-
::apply(static_cast<F&&>(fn), static_cast<Args&&>(args)...));
380+
bsoncxx_returns(impl_invoke::invoker<std::is_member_object_pointer<Fd>::value,
381+
std::is_member_function_pointer<Fd>::value> //
382+
::apply(static_cast<F&&>(fn), static_cast<Args&&>(args)...));
389383
} invoke;
390384

391-
#pragma pop_macro("RETURNS")
392-
393385
/**
394386
* @brief Yields the type that would result from invoking F with the given arguments.
395387
*

0 commit comments

Comments
 (0)