diff --git a/include/peejay/dom.hpp b/include/peejay/dom.hpp index 5562f1a..604d9dc 100644 --- a/include/peejay/dom.hpp +++ b/include/peejay/dom.hpp @@ -57,22 +57,19 @@ struct element : variant { using variant::variant; struct element *parent = nullptr; + element () noexcept = default; element (element const &rhs) = delete; element (element &&rhs) noexcept : variant (std::move (static_cast (rhs))) { adjust_parents (); } + ~element () noexcept = default; element &operator= (element const &rhs) = delete; - element &operator= (element &&rhs) noexcept { - if (this != &rhs) { - static_cast (this)->operator= ( - std::move (static_cast (rhs))); - adjust_parents (); - } - return *this; - } + element &operator= (element &&rhs) noexcept; + bool operator== (element const &rhs) const; + bool operator!= (element const &rhs) const { return !operator== (rhs); } /// Evaluate a JSON pointer (RFC6901). element *eval_pointer (u8string_view s); @@ -98,6 +95,17 @@ struct element : variant { static constexpr std::optional stoui (u8string_view s); }; +// operator= +// ~~~~~~~~~ +inline element &element::operator= (element &&rhs) noexcept { + if (this != &rhs) { + static_cast (this)->operator= ( + std::move (static_cast (rhs))); + adjust_parents (); + } + return *this; +} + // operator== // ~~~~~~~~~~ inline bool element::operator== (element const &rhs) const { @@ -152,7 +160,7 @@ inline std::optional> decimal ( auto prefix = 0U; auto pos = u8string_view::size_type{0}; auto const len = s.length (); - for (; pos < len && std::isdigit (s[pos]); ++pos) { + for (; pos < len && std::isdigit (s[pos]) != 0; ++pos) { prefix = prefix * 10U + static_cast (s[pos] - '0'); } if (pos == 0) { @@ -192,7 +200,7 @@ inline std::optional element::eval_relative_pointer (u8string_view s) { // - If the referenced value is an object member within an object, then the // new referenced value is that object. - if (s.empty () || !std::isdigit (s.front ())) { + if (s.empty () || std::isdigit (s.front ()) == 0) { return {}; } auto const d1 = decimal (s); @@ -345,7 +353,7 @@ constexpr std::optional element::stoui (u8string_view s) { } auto res = 0U; for (auto const c : s) { - if (!std::isdigit (static_cast (c))) { + if (std::isdigit (static_cast (c)) == 0) { return {}; } res = res * 10U + static_cast (c - '0'); diff --git a/unittests/test_small_vector.cpp b/unittests/test_small_vector.cpp index d1b28e7..af6fec8 100644 --- a/unittests/test_small_vector.cpp +++ b/unittests/test_small_vector.cpp @@ -13,6 +13,7 @@ #include +#include #include #include @@ -24,7 +25,8 @@ using peejay::small_vector; using testing::ElementsAre; -struct copy_ex : public std::domain_error { +class copy_ex : public std::domain_error { +public: copy_ex () : std::domain_error{"copy"} {} }; struct copy_throws { @@ -76,7 +78,7 @@ struct move_throws { move_throws () = default; explicit move_throws (int v_) : v{v_} {} move_throws (move_throws const&) noexcept = default; - // NOLINTNEXTLINE(bugprone-exception-escape) + // NOLINTNEXTLINE move_throws (move_throws&& rhs) { if (throws) { throw move_ex{}; @@ -87,7 +89,7 @@ struct move_throws { ~move_throws () noexcept = default; move_throws& operator= (move_throws const&) noexcept = default; - // NOLINTNEXTLINE(bugprone-exception-escape) + // NOLINTNEXTLINE move_throws& operator= (move_throws&& rhs) { if (&rhs != this) { if (throws) { @@ -134,7 +136,7 @@ static_assert ( // NOLINTNEXTLINE TEST (SmallVector, DefaultCtor) { - peejay::small_vector b; + peejay::small_vector const b; EXPECT_EQ (0U, b.size ()) << "expected the initial size to be number number of stack elements"; EXPECT_EQ (8U, b.capacity ()); @@ -214,7 +216,7 @@ TEST (SmallVector, CtorInitializerList) { // NOLINTNEXTLINE TEST (SmallVector, CtorInitializerList2) { - peejay::small_vector b{1, 2, 3, 4}; + peejay::small_vector const b{1, 2, 3, 4}; EXPECT_THAT (b, ::testing::ElementsAre (1, 2, 3, 4)); } @@ -222,7 +224,7 @@ TEST (SmallVector, CtorInitializerList2) { TEST (SmallVector, CtorCopy) { peejay::small_vector const b{3, 5}; // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) - peejay::small_vector c = b; + peejay::small_vector const c = b; EXPECT_EQ (2U, c.size ()); EXPECT_THAT (c, ElementsAre (3, 5)); } @@ -629,6 +631,7 @@ TEST (SmallVector, IteratorNonConst) { // I populate the buffer manually here to ensure coverage of basic iterator // operations, but use std::iota() elsewhere to keep the tests simple. int value = 42; + // NOLINTNEXTLINE (modernize-loop-convert) for (decltype (buffer)::iterator it = buffer.begin (), end = buffer.end (); it != end; ++it) { *it = value++; @@ -637,6 +640,7 @@ TEST (SmallVector, IteratorNonConst) { { // Manually copy the contents of the buffer to a new vector. std::vector actual; + // NOLINTNEXTLINE (modernize-loop-convert) for (decltype (buffer)::iterator it = buffer.begin (), end = buffer.end (); it != end; ++it) { actual.push_back (*it); @@ -700,7 +704,7 @@ TEST (SmallVector, IteratorConstReverse) { return buffer; }(); - std::vector actual (cbuffer.rbegin (), cbuffer.rend ()); + std::vector const actual (cbuffer.rbegin (), cbuffer.rend ()); EXPECT_THAT (actual, ::testing::ElementsAre (45, 44, 43, 42)); }