summaryrefslogtreecommitdiff
path: root/AK/String.h
diff options
context:
space:
mode:
authorLenny Maiorani <lenny@colorado.edu>2021-01-10 16:29:28 -0700
committerAndreas Kling <kling@serenityos.org>2021-01-12 09:11:45 +0100
commite6f907a1556757c623fe660df0a43faf1b3d0eae (patch)
treea3a07081ec2ebdac050d776c61d2c908459bf343 /AK/String.h
parent9dc44bf8c427160bafd87205c42201cf9b11c0b4 (diff)
downloadserenity-e6f907a1556757c623fe660df0a43faf1b3d0eae.zip
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.
Diffstat (limited to 'AK/String.h')
-rw-r--r--AK/String.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/AK/String.h b/AK/String.h
index 3582e54ce3..c30f72e258 100644
--- a/AK/String.h
+++ b/AK/String.h
@@ -58,9 +58,9 @@ namespace AK {
class String {
public:
- ~String() { }
+ ~String() = default;
- String() { }
+ String() = default;
String(const StringView&);
String(const String& other)
@@ -153,7 +153,13 @@ public:
[[nodiscard]] bool copy_characters_to_buffer(char* buffer, size_t buffer_size) const;
- ALWAYS_INLINE ReadonlyBytes bytes() const { return m_impl ? m_impl->bytes() : nullptr; }
+ ALWAYS_INLINE ReadonlyBytes bytes() const
+ {
+ if (m_impl) {
+ return m_impl->bytes();
+ }
+ return {};
+ }
ALWAYS_INLINE const char& operator[](size_t i) const
{