Skip to content

Conversation

@vector-of-bool
Copy link
Contributor

This PR is a continuation of the work for CXX-2625. The PR itself contains many commits from the string_view PR, since this was created from that work. The relevant commits for optional<T> begin with 947d289.

optional<std::string> string2 = std::move(c_str);
CHECK(string == c_str);
CHECK(string2 == c_str);
}
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@kevinAlbs kevinAlbs self-requested a review February 5, 2024 21:31
Copy link
Contributor

@eramongodb eramongodb left a 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.

Comment on lines 1 to 10
#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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a 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>>,
Copy link
Collaborator

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 neither std::in_place_t nor std::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*() &");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_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&");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_assert_has_value("operator*() const&");
_assert_has_value("operator*() const&&");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants