1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

AK: Simplify constructors and conversions from nullptr_t

Problem:
- Many constructors are defined as `{}` rather than using the ` =
  default` compiler-provided constructor.
- Some types provide an implicit conversion operator from `nullptr_t`
  instead of requiring the caller to default construct. This violates
  the C++ Core Guidelines suggestion to declare single-argument
  constructors explicit
  (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit).

Solution:
- Change default constructors to use the compiler-provided default
  constructor.
- Remove implicit conversion operators from `nullptr_t` and change
  usage to enforce type consistency without conversion.
This commit is contained in:
Lenny Maiorani 2021-01-10 16:29:28 -07:00 committed by Andreas Kling
parent 9dc44bf8c4
commit e6f907a155
105 changed files with 300 additions and 244 deletions

View file

@ -118,12 +118,12 @@ OwnPtr<Table> Table::parse(Vector<StringView>::ConstIterator& lines)
auto peek_it = lines;
auto first_line = *peek_it;
if (!first_line.starts_with('|'))
return nullptr;
return {};
++peek_it;
if (peek_it.is_end())
return nullptr;
return {};
auto header_segments = first_line.split_view('|', true);
auto header_delimiters = peek_it->split_view('|', true);
@ -141,10 +141,10 @@ OwnPtr<Table> Table::parse(Vector<StringView>::ConstIterator& lines)
++peek_it;
if (header_delimiters.size() != header_segments.size())
return nullptr;
return {};
if (header_delimiters.is_empty())
return nullptr;
return {};
size_t total_width = 0;
@ -154,7 +154,7 @@ OwnPtr<Table> Table::parse(Vector<StringView>::ConstIterator& lines)
for (size_t i = 0; i < header_segments.size(); ++i) {
auto text_option = Text::parse(header_segments[i]);
if (!text_option.has_value())
return nullptr; // An invalid 'text' in the header should just fail the table parse.
return {}; // An invalid 'text' in the header should just fail the table parse.
auto text = text_option.release_value();
auto& column = table->m_columns[i];