mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-13 11:17:06 +07:00
operator* and operator-> for uresult
This commit is contained in:
@@ -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_);
|
||||
}
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user