diff options
author | ADAM David Alan Martin <adam.martin@10gen.com> | 2018-09-11 16:14:28 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2018-09-11 16:14:28 -0400 |
commit | 80e8f97ac01abb879c462712d9765716db5c675a (patch) | |
tree | 32b75652d78e11d406113baea31c1ef302e0f492 | |
parent | 7ba9a08f3d5924a5b605b2a19938eed78f7dbf86 (diff) | |
download | mongo-80e8f97ac01abb879c462712d9765716db5c675a.tar.gz |
SERVER-37075 Make `unique_function<...>::nil` not break on MacOS
Some MacOS headers `#define nil`, because of Objective-C[++]. Use,
instead, a name for the internal dummy argument that won't collide.
-rw-r--r-- | src/mongo/util/functional.h | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/mongo/util/functional.h b/src/mongo/util/functional.h index 5be238c9dde..f809fe8311a 100644 --- a/src/mongo/util/functional.h +++ b/src/mongo/util/functional.h @@ -48,15 +48,16 @@ class unique_function; template <typename RetType, typename... Args> class unique_function<RetType(Args...)> { private: - // `nilbase` is used as a base for the `nil` type, to prevent it from being an aggregate. - struct nilbase { + // `TagTypeBase` is used as a base for the `TagType` type, to prevent it from being an + // aggregate. + struct TagTypeBase { protected: - nilbase() = default; + TagTypeBase() = default; }; - // `nil` is used as a placeholder type in parameter lists for `enable_if` clauses. They have to - // be real parameters, not template parameters, due to MSVC limitations. - class nil : nilbase { - nil() = default; + // `TagType` is used as a placeholder type in parameter lists for `enable_if` clauses. They + // have to be real parameters, not template parameters, due to MSVC limitations. + class TagType : TagTypeBase { + TagType() = default; friend unique_function; }; @@ -93,9 +94,10 @@ public: // requirements are met. They must be concrete parameters not template parameters to work // around bugs in some compilers that we presently use. We may be able to revisit this // design after toolchain upgrades for C++17. - std::enable_if_t<stdx::is_invocable_r<RetType, Functor, Args...>::value, nil> = makeNil(), - std::enable_if_t<std::is_move_constructible<Functor>::value, nil> = makeNil(), - std::enable_if_t<!std::is_same<Functor, unique_function>::value, nil> = makeNil()) + std::enable_if_t<stdx::is_invocable_r<RetType, Functor, Args...>::value, TagType> = + makeTag(), + std::enable_if_t<std::is_move_constructible<Functor>::value, TagType> = makeTag(), + std::enable_if_t<!std::is_same<Functor, unique_function>::value, TagType> = makeTag()) : impl(makeImpl(std::forward<Functor>(functor))) {} unique_function(std::nullptr_t) noexcept {} @@ -122,9 +124,9 @@ public: operator std::function<Signature>() const = delete; private: - // The `nil` type cannot be constructed as a default function-parameter in Clang. So we use a - // static member function that initializes that default parameter. - static nil makeNil() { + // The `TagType` type cannot be constructed as a default function-parameter in Clang. So we use + // a static member function that initializes that default parameter. + static TagType makeTag() { return {}; } |