-
Notifications
You must be signed in to change notification settings - Fork 548
[CXX-2625] Bring our own optional<T> #1075
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
Conversation
| optional<std::string> string2 = std::move(c_str); | ||
| CHECK(string == c_str); | ||
| CHECK(string2 == c_str); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding more exhaustive tests of use the new API. Example: https://gist.github.com/kevinAlbs/5f3ddccb491f5e4c42633589781e1909
Tests may have helped revealed earlier issues (e.g. converting move constructors and swap). These tests may help cross-reference with cppreference to determine any missing API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added many more cases, including those from your gist. Should get better coverage now.
eramongodb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this PR. Some minor suggestions remaining; otherwise, LGTM.
| #pragma once | ||
|
|
||
| #define BSONCXX_FEATURE_HaveCxxStdlibVersionMacros - | ||
| #ifdef __has_include | ||
| #if __has_include(<version>) | ||
| #include <version> | ||
| #undef BSONCXX_FEATURE_HaveCxxStdlibVersionMacros | ||
| #define BSONCXX_FEATURE_HaveCxxStdlibVersionMacros + | ||
| #endif | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #pragma once | |
| #define BSONCXX_FEATURE_HaveCxxStdlibVersionMacros - | |
| #ifdef __has_include | |
| #if __has_include(<version>) | |
| #include <version> | |
| #undef BSONCXX_FEATURE_HaveCxxStdlibVersionMacros | |
| #define BSONCXX_FEATURE_HaveCxxStdlibVersionMacros + | |
| #endif | |
| #endif |
Remove stray, unused header. (Added unintentionally?)
| CHECK(hashit(a) == hashit(b)); | ||
| b.emplace(41); | ||
| CHECK(hashit(41) == hashit(b)); | ||
| CHECK(hashit(a) != hashit(b)); // (Extremely probable, but not certain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CHECK(hashit(a) != hashit(b)); // (Extremely probable, but not certain) | |
| CHECK_NOFAIL(hashit(a) != hashit(b)); // (Extremely probable, but not certain) |
Consider using CHECK_NOFAIL for consistency with the "not certain" description.
kevinAlbs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one possible added condition and minor error message fixups.
| struct enable_opt_value_conversion // | ||
| : bsoncxx::detail::conjunction< // | ||
| std::is_constructible<To, From&&>, | ||
| bsoncxx::detail::negation<bsoncxx::detail::is_alike<From, in_place_t>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://en.cppreference.com/w/cpp/utility/optional/optional notes this condition for (8):
std::decay_t<U>(until C++20)std::remove_cvref_t<U>(since C++20) is neitherstd::in_place_tnorstd::optional<T>
Is checking for std::optional<T> also needed? Example:
bsoncxx::detail::conjunction<
bsoncxx::detail::negation<bsoncxx::detail::is_alike<From, in_place_t>>, //
bsoncxx::detail::negation<bsoncxx::detail::is_alike<From, optional<To>>> //
>,I am not sure it is needed. I was unable to come up with a test case that showed any behavior difference.
| return this->_storage.value; | ||
| } | ||
| bsoncxx_cxx14_constexpr rvalue_reference operator*() && noexcept { | ||
| _assert_has_value("operator*() &"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| _assert_has_value("operator*() &"); | |
| _assert_has_value("operator*() &&"); |
| return static_cast<rvalue_reference>(**this); | ||
| } | ||
| bsoncxx_cxx14_constexpr const_rvalue_reference operator*() const&& noexcept { | ||
| _assert_has_value("operator*() const&"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| _assert_has_value("operator*() const&"); | |
| _assert_has_value("operator*() const&&"); |
This PR is a continuation of the work for CXX-2625. The PR itself contains many commits from the
string_viewPR, since this was created from that work. The relevant commits foroptional<T>begin with 947d289.