refactor: rename member vars, adding _ at the end

This commit is contained in:
ToruNiina
2024-06-19 01:55:25 +09:00
parent 013d1e396f
commit 7149b3cb29
2 changed files with 56 additions and 56 deletions

View File

@@ -183,27 +183,27 @@ struct result
using value_type = typename success_type::value_type; using value_type = typename success_type::value_type;
using error_type = typename failure_type::value_type; using error_type = typename failure_type::value_type;
result(success_type s): is_ok_(true), succ(std::move(s)) {} result(success_type s): is_ok_(true), succ_(std::move(s)) {}
result(failure_type f): is_ok_(false), fail(std::move(f)) {} result(failure_type f): is_ok_(false), fail_(std::move(f)) {}
template<typename U, cxx::enable_if_t<cxx::conjunction< template<typename U, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, value_type>>, cxx::negation<std::is_same<cxx::remove_cvref_t<U>, value_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, value_type> std::is_convertible<cxx::remove_cvref_t<U>, value_type>
>::value, std::nullptr_t> = nullptr> >::value, std::nullptr_t> = nullptr>
result(success<U> s): is_ok_(true), succ(std::move(s.value)) {} result(success<U> s): is_ok_(true), succ_(std::move(s.value)) {}
template<typename U, cxx::enable_if_t<cxx::conjunction< template<typename U, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, error_type>>, cxx::negation<std::is_same<cxx::remove_cvref_t<U>, error_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, error_type> std::is_convertible<cxx::remove_cvref_t<U>, error_type>
>::value, std::nullptr_t> = nullptr> >::value, std::nullptr_t> = nullptr>
result(failure<U> f): is_ok_(false), fail(std::move(f.value)) {} result(failure<U> f): is_ok_(false), fail_(std::move(f.value)) {}
result& operator=(success_type s) result& operator=(success_type s)
{ {
this->cleanup(); this->cleanup();
this->is_ok_ = true; this->is_ok_ = true;
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(s)); auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(s));
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
return *this; return *this;
} }
@@ -211,8 +211,8 @@ struct result
{ {
this->cleanup(); this->cleanup();
this->is_ok_ = false; this->is_ok_ = false;
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(f)); auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(f));
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
return *this; return *this;
} }
@@ -222,8 +222,8 @@ struct result
{ {
this->cleanup(); this->cleanup();
this->is_ok_ = true; this->is_ok_ = true;
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(s.value)); auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(s.value));
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
return *this; return *this;
} }
@@ -232,8 +232,8 @@ struct result
{ {
this->cleanup(); this->cleanup();
this->is_ok_ = false; this->is_ok_ = false;
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(f.value)); auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(f.value));
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
return *this; return *this;
} }
@@ -244,14 +244,14 @@ struct result
{ {
if(other.is_ok()) if(other.is_ok())
{ {
auto tmp = ::new(std::addressof(this->succ)) success_type(other.as_ok()); auto tmp = ::new(std::addressof(this->succ_)) success_type(other.as_ok());
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
} }
else else
{ {
auto tmp = ::new(std::addressof(this->fail)) failure_type(other.as_err()); auto tmp = ::new(std::addressof(this->fail_)) failure_type(other.as_err());
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
} }
} }
@@ -259,14 +259,14 @@ struct result
{ {
if(other.is_ok()) if(other.is_ok())
{ {
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok())); auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
} }
else else
{ {
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err())); auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
} }
} }
@@ -276,14 +276,14 @@ struct result
this->cleanup(); this->cleanup();
if(other.is_ok()) if(other.is_ok())
{ {
auto tmp = ::new(std::addressof(this->succ)) success_type(other.as_ok()); auto tmp = ::new(std::addressof(this->succ_)) success_type(other.as_ok());
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
} }
else else
{ {
auto tmp = ::new(std::addressof(this->fail)) failure_type(other.as_err()); auto tmp = ::new(std::addressof(this->fail_)) failure_type(other.as_err());
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
} }
is_ok_ = other.is_ok(); is_ok_ = other.is_ok();
@@ -294,14 +294,14 @@ struct result
this->cleanup(); this->cleanup();
if(other.is_ok()) if(other.is_ok())
{ {
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok())); auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
} }
else else
{ {
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err())); auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
} }
is_ok_ = other.is_ok(); is_ok_ = other.is_ok();
@@ -318,14 +318,14 @@ struct result
{ {
if(other.is_ok()) if(other.is_ok())
{ {
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok())); auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
} }
else else
{ {
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err())); auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
} }
} }
@@ -341,14 +341,14 @@ struct result
this->cleanup(); this->cleanup();
if(other.is_ok()) if(other.is_ok())
{ {
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok())); auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ)); assert(tmp == std::addressof(this->succ_));
(void)tmp; (void)tmp;
} }
else else
{ {
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err())); auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail)); assert(tmp == std::addressof(this->fail_));
(void)tmp; (void)tmp;
} }
is_ok_ = other.is_ok(); is_ok_ = other.is_ok();
@@ -366,7 +366,7 @@ struct result
{ {
throw bad_result_access("toml::result: bad unwrap" + cxx::to_string(loc)); throw bad_result_access("toml::result: bad unwrap" + cxx::to_string(loc));
} }
return this->succ.get(); return this->succ_.get();
} }
value_type const& unwrap(cxx::source_location loc = cxx::source_location::current()) const value_type const& unwrap(cxx::source_location loc = cxx::source_location::current()) const
{ {
@@ -374,18 +374,18 @@ struct result
{ {
throw bad_result_access("toml::result: bad unwrap" + cxx::to_string(loc)); throw bad_result_access("toml::result: bad unwrap" + cxx::to_string(loc));
} }
return this->succ.get(); return this->succ_.get();
} }
value_type& unwrap_or(value_type& opt) noexcept value_type& unwrap_or(value_type& opt) noexcept
{ {
if(this->is_err()) {return opt;} if(this->is_err()) {return opt;}
return this->succ.get(); return this->succ_.get();
} }
value_type const& unwrap_or(value_type const& opt) const noexcept value_type const& unwrap_or(value_type const& opt) const noexcept
{ {
if(this->is_err()) {return opt;} if(this->is_err()) {return opt;}
return this->succ.get(); return this->succ_.get();
} }
error_type& unwrap_err(cxx::source_location loc = cxx::source_location::current()) error_type& unwrap_err(cxx::source_location loc = cxx::source_location::current())
@@ -394,7 +394,7 @@ struct result
{ {
throw bad_result_access("toml::result: bad unwrap_err" + cxx::to_string(loc)); throw bad_result_access("toml::result: bad unwrap_err" + cxx::to_string(loc));
} }
return this->fail.get(); return this->fail_.get();
} }
error_type const& unwrap_err(cxx::source_location loc = cxx::source_location::current()) const error_type const& unwrap_err(cxx::source_location loc = cxx::source_location::current()) const
{ {
@@ -402,29 +402,29 @@ struct result
{ {
throw bad_result_access("toml::result: bad unwrap_err" + cxx::to_string(loc)); throw bad_result_access("toml::result: bad unwrap_err" + cxx::to_string(loc));
} }
return this->fail.get(); return this->fail_.get();
} }
value_type& as_ok() noexcept value_type& as_ok() noexcept
{ {
assert(this->is_ok()); assert(this->is_ok());
return this->succ.get(); return this->succ_.get();
} }
value_type const& as_ok() const noexcept value_type const& as_ok() const noexcept
{ {
assert(this->is_ok()); assert(this->is_ok());
return this->succ.get(); return this->succ_.get();
} }
error_type& as_err() noexcept error_type& as_err() noexcept
{ {
assert(this->is_err()); assert(this->is_err());
return this->fail.get(); return this->fail_.get();
} }
error_type const& as_err() const noexcept error_type const& as_err() const noexcept
{ {
assert(this->is_err()); assert(this->is_err());
return this->fail.get(); return this->fail_.get();
} }
private: private:
@@ -436,8 +436,8 @@ struct result
#pragma GCC diagnostic ignored "-Wduplicated-branches" #pragma GCC diagnostic ignored "-Wduplicated-branches"
#endif #endif
if(this->is_ok_) {this->succ.~success_type();} if(this->is_ok_) {this->succ_.~success_type();}
else {this->fail.~failure_type();} else {this->fail_.~failure_type();}
#if defined(__GNUC__) && ! defined(__clang__) #if defined(__GNUC__) && ! defined(__clang__)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
@@ -450,8 +450,8 @@ struct result
bool is_ok_; bool is_ok_;
union union
{ {
success_type succ; success_type succ_;
failure_type fail; failure_type fail_;
}; };
}; };

View File

@@ -23,25 +23,25 @@ struct storage
{ {
using value_type = T; using value_type = T;
explicit storage(value_type v): ptr(cxx::make_unique<T>(std::move(v))) {} explicit storage(value_type v): ptr_(cxx::make_unique<T>(std::move(v))) {}
~storage() = default; ~storage() = default;
storage(const storage& rhs): ptr(cxx::make_unique<T>(*rhs.ptr)) {} storage(const storage& rhs): ptr_(cxx::make_unique<T>(*rhs.ptr_)) {}
storage& operator=(const storage& rhs) storage& operator=(const storage& rhs)
{ {
this->ptr = cxx::make_unique<T>(*rhs.ptr); this->ptr_ = cxx::make_unique<T>(*rhs.ptr_);
return *this; return *this;
} }
storage(storage&&) = default; storage(storage&&) = default;
storage& operator=(storage&&) = default; storage& operator=(storage&&) = default;
bool is_ok() const noexcept {return static_cast<bool>(ptr);} bool is_ok() const noexcept {return static_cast<bool>(ptr_);}
value_type& get() const noexcept {return *ptr;} value_type& get() const noexcept {return *ptr_;}
private: private:
std::unique_ptr<value_type> ptr; std::unique_ptr<value_type> ptr_;
}; };
} // detail } // detail