Skip to content

Commit

Permalink
refactor: rename member vars, adding _ at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
ToruNiina committed Jun 18, 2024
1 parent 013d1e3 commit 7149b3c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
100 changes: 50 additions & 50 deletions include/toml11/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,36 @@ struct result
using value_type = typename success_type::value_type;
using error_type = typename failure_type::value_type;

result(success_type s): is_ok_(true), succ(std::move(s)) {}
result(failure_type f): is_ok_(false), fail(std::move(f)) {}
result(success_type s): is_ok_(true), succ_(std::move(s)) {}
result(failure_type f): is_ok_(false), fail_(std::move(f)) {}

template<typename U, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, value_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, value_type>
>::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<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, error_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, error_type>
>::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)
{
this->cleanup();
this->is_ok_ = true;
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(s));
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(s));
assert(tmp == std::addressof(this->succ_));
(void)tmp;
return *this;
}
result& operator=(failure_type f)
{
this->cleanup();
this->is_ok_ = false;
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(f));
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(f));
assert(tmp == std::addressof(this->fail_));
(void)tmp;
return *this;
}
Expand All @@ -222,8 +222,8 @@ struct result
{
this->cleanup();
this->is_ok_ = true;
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(s.value));
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(s.value));
assert(tmp == std::addressof(this->succ_));
(void)tmp;
return *this;
}
Expand All @@ -232,8 +232,8 @@ struct result
{
this->cleanup();
this->is_ok_ = false;
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(f.value));
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(f.value));
assert(tmp == std::addressof(this->fail_));
(void)tmp;
return *this;
}
Expand All @@ -244,29 +244,29 @@ struct result
{
if(other.is_ok())
{
auto tmp = ::new(std::addressof(this->succ)) success_type(other.as_ok());
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(other.as_ok());
assert(tmp == std::addressof(this->succ_));
(void)tmp;
}
else
{
auto tmp = ::new(std::addressof(this->fail)) failure_type(other.as_err());
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(other.as_err());
assert(tmp == std::addressof(this->fail_));
(void)tmp;
}
}
result(result&& other): is_ok_(other.is_ok())
{
if(other.is_ok())
{
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ_));
(void)tmp;
}
else
{
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail_));
(void)tmp;
}
}
Expand All @@ -276,14 +276,14 @@ struct result
this->cleanup();
if(other.is_ok())
{
auto tmp = ::new(std::addressof(this->succ)) success_type(other.as_ok());
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(other.as_ok());
assert(tmp == std::addressof(this->succ_));
(void)tmp;
}
else
{
auto tmp = ::new(std::addressof(this->fail)) failure_type(other.as_err());
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(other.as_err());
assert(tmp == std::addressof(this->fail_));
(void)tmp;
}
is_ok_ = other.is_ok();
Expand All @@ -294,14 +294,14 @@ struct result
this->cleanup();
if(other.is_ok())
{
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ_));
(void)tmp;
}
else
{
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail_));
(void)tmp;
}
is_ok_ = other.is_ok();
Expand All @@ -318,14 +318,14 @@ struct result
{
if(other.is_ok())
{
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ_));
(void)tmp;
}
else
{
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail_));
(void)tmp;
}
}
Expand All @@ -341,14 +341,14 @@ struct result
this->cleanup();
if(other.is_ok())
{
auto tmp = ::new(std::addressof(this->succ)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ));
auto tmp = ::new(std::addressof(this->succ_)) success_type(std::move(other.as_ok()));
assert(tmp == std::addressof(this->succ_));
(void)tmp;
}
else
{
auto tmp = ::new(std::addressof(this->fail)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail));
auto tmp = ::new(std::addressof(this->fail_)) failure_type(std::move(other.as_err()));
assert(tmp == std::addressof(this->fail_));
(void)tmp;
}
is_ok_ = other.is_ok();
Expand All @@ -366,26 +366,26 @@ struct result
{
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
{
if(this->is_err())
{
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
{
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
{
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())
Expand All @@ -394,37 +394,37 @@ struct result
{
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
{
if(this->is_ok())
{
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
{
assert(this->is_ok());
return this->succ.get();
return this->succ_.get();
}
value_type const& as_ok() const noexcept
{
assert(this->is_ok());
return this->succ.get();
return this->succ_.get();
}

error_type& as_err() noexcept
{
assert(this->is_err());
return this->fail.get();
return this->fail_.get();
}
error_type const& as_err() const noexcept
{
assert(this->is_err());
return this->fail.get();
return this->fail_.get();
}

private:
Expand All @@ -436,8 +436,8 @@ struct result
#pragma GCC diagnostic ignored "-Wduplicated-branches"
#endif

if(this->is_ok_) {this->succ.~success_type();}
else {this->fail.~failure_type();}
if(this->is_ok_) {this->succ_.~success_type();}
else {this->fail_.~failure_type();}

#if defined(__GNUC__) && ! defined(__clang__)
#pragma GCC diagnostic pop
Expand All @@ -450,8 +450,8 @@ struct result
bool is_ok_;
union
{
success_type succ;
failure_type fail;
success_type succ_;
failure_type fail_;
};
};

Expand Down
12 changes: 6 additions & 6 deletions include/toml11/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ struct storage
{
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(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)
{
this->ptr = cxx::make_unique<T>(*rhs.ptr);
this->ptr_ = cxx::make_unique<T>(*rhs.ptr_);
return *this;
}

storage(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:
std::unique_ptr<value_type> ptr;
std::unique_ptr<value_type> ptr_;
};

} // detail
Expand Down

0 comments on commit 7149b3c

Please sign in to comment.