ladybird/Userland/Libraries/LibWeb/DOM/Position.h
Daniel Bertalan 4296425bd8 Everywhere: Remove redundant inequality comparison operators
C++20 can automatically synthesize `operator!=` from `operator==`, so
there is no point in writing such functions by hand if all they do is
call through to `operator==`.

This fixes a compile error with compilers that implement P2468 (Clang
16 currently). This paper restores the C++17 behavior that if both
`T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be
rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators
makes the rewriting possible again.
See https://reviews.llvm.org/D134529#3853062
2022-11-06 10:25:08 -07:00

57 lines
1.3 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/RefPtr.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
class Position {
public:
Position() = default;
Position(Node&, unsigned offset);
bool is_valid() const { return m_node.ptr(); }
Node* node() { return m_node.cell(); }
Node const* node() const { return m_node.cell(); }
unsigned offset() const { return m_offset; }
bool offset_is_at_end_of_node() const;
void set_offset(unsigned value) { m_offset = value; }
bool increment_offset();
bool decrement_offset();
bool operator==(Position const& other) const
{
return m_node.ptr() == other.m_node.ptr() && m_offset == other.m_offset;
}
String to_string() const;
private:
JS::Handle<Node> m_node;
unsigned m_offset { 0 };
};
}
namespace AK {
template<>
struct Formatter<Web::DOM::Position> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, Web::DOM::Position const& value)
{
return Formatter<StringView>::format(builder, value.to_string());
}
};
}