operator* and operator-> for uresult

This commit is contained in:
BlackMATov
2023-02-18 02:51:12 +07:00
parent d6ba3d8ce4
commit 46ff71ea79
4 changed files with 111 additions and 21 deletions

View File

@@ -3115,10 +3115,18 @@ namespace meta_hpp
[[nodiscard]] bool has_value() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] uvalue& get_value() &;
[[nodiscard]] uvalue&& get_value() &&;
[[nodiscard]] const uvalue& get_value() const&;
[[nodiscard]] const uvalue&& get_value() const&&;
[[nodiscard]] uvalue* operator->() noexcept;
[[nodiscard]] const uvalue* operator->() const noexcept;
[[nodiscard]] uvalue& operator*() & noexcept;
[[nodiscard]] uvalue&& operator*() && noexcept;
[[nodiscard]] const uvalue& operator*() const& noexcept;
[[nodiscard]] const uvalue&& operator*() const&& noexcept;
[[nodiscard]] uvalue& get_value() & noexcept;
[[nodiscard]] uvalue&& get_value() && noexcept;
[[nodiscard]] const uvalue& get_value() const& noexcept;
[[nodiscard]] const uvalue&& get_value() const&& noexcept;
[[nodiscard]] error_code get_error() const noexcept;
@@ -9284,19 +9292,44 @@ namespace meta_hpp
return has_value();
}
inline uvalue& uresult::get_value() & {
inline uvalue* uresult::operator->() noexcept {
return std::addressof(value_);
}
inline const uvalue* uresult::operator->() const noexcept {
return std::addressof(value_);
}
inline uvalue& uresult::operator*() & noexcept {
return value_;
}
inline uvalue&& uresult::get_value() && {
inline uvalue&& uresult::operator*() && noexcept {
return std::move(value_);
}
inline const uvalue& uresult::get_value() const& {
inline const uvalue& uresult::operator*() const& noexcept {
return value_;
}
inline const uvalue&& uresult::get_value() const&& {
inline const uvalue&& uresult::operator*() const&& noexcept {
// NOLINTNEXTLINE(*-move-const-arg)
return std::move(value_);
}
inline uvalue& uresult::get_value() & noexcept {
return value_;
}
inline uvalue&& uresult::get_value() && noexcept {
return std::move(value_);
}
inline const uvalue& uresult::get_value() const& noexcept {
return value_;
}
inline const uvalue&& uresult::get_value() const&& noexcept {
// NOLINTNEXTLINE(*-move-const-arg)
return std::move(value_);
}

View File

@@ -297,10 +297,34 @@ TEST_CASE("meta/meta_utilities/uresult") {
static_assert(std::is_same_v<const meta::uvalue&, decltype(std::declval<const meta::uresult&>().get_value())>);
static_assert(std::is_same_v<const meta::uvalue&&, decltype(std::declval<const meta::uresult&&>().get_value())>);
meta::uresult res{ivec2{42, 21}};
CHECK(res.get_value().as<ivec2>() == ivec2{42, 21});
CHECK(std::move(res).get_value().as<ivec2>() == ivec2{42, 21});
CHECK(std::as_const(res).get_value().as<ivec2>() == ivec2{42, 21});
CHECK(std::move(std::as_const(res)).get_value().as<ivec2>() == ivec2{42, 21});
static_assert(std::is_same_v<meta::uvalue&, decltype(std::declval<meta::uresult&>().operator*())>);
static_assert(std::is_same_v<meta::uvalue&&, decltype(std::declval<meta::uresult&&>().operator*())>);
static_assert(std::is_same_v<const meta::uvalue&, decltype(std::declval<const meta::uresult&>().operator*())>);
static_assert(std::is_same_v<const meta::uvalue&&, decltype(std::declval<const meta::uresult&&>().operator*())>);
static_assert(std::is_same_v<meta::uvalue*, decltype(std::declval<meta::uresult&>().operator->())>);
static_assert(std::is_same_v<const meta::uvalue*, decltype(std::declval<const meta::uresult&>().operator->())>);
{
meta::uresult res{ivec2{42, 21}};
CHECK(res.get_value().as<ivec2>() == ivec2{42, 21});
CHECK(std::move(res).get_value().as<ivec2>() == ivec2{42, 21});
CHECK(std::as_const(res).get_value().as<ivec2>() == ivec2{42, 21});
CHECK(std::move(std::as_const(res)).get_value().as<ivec2>() == ivec2{42, 21});
}
{
meta::uresult res{ivec2{42, 21}};
CHECK((*res).as<ivec2>() == ivec2{42, 21});
CHECK((*std::move(res)).as<ivec2>() == ivec2{42, 21});
CHECK((*std::as_const(res)).as<ivec2>() == ivec2{42, 21});
CHECK((*std::move(std::as_const(res))).as<ivec2>() == ivec2{42, 21});
}
{
meta::uresult res{ivec2{42, 21}};
CHECK(res->as<ivec2>() == ivec2{42, 21});
CHECK(std::as_const(res)->as<ivec2>() == ivec2{42, 21});
}
}
}