More explicit naming for visit and handleEvents types and fix lint comments

This commit is contained in:
kimci86 2025-01-25 23:37:48 +01:00 committed by Chris Thrasher
parent 37c87ee11e
commit 23afdc2f9e
4 changed files with 18 additions and 17 deletions

View File

@ -346,8 +346,8 @@ public:
/// \return The result of applying the visitor to the event /// \return The result of applying the visitor to the event
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename Visitor>
decltype(auto) visit(T&& visitor); decltype(auto) visit(Visitor&& visitor);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Apply a visitor to the event /// \brief Apply a visitor to the event
@ -357,8 +357,8 @@ public:
/// \return The result of applying the visitor to the event /// \return The result of applying the visitor to the event
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename Visitor>
decltype(auto) visit(T&& visitor) const; decltype(auto) visit(Visitor&& visitor) const;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -79,18 +79,18 @@ const TEventSubtype* Event::getIf() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename Visitor>
decltype(auto) Event::visit(T&& visitor) decltype(auto) Event::visit(Visitor&& visitor)
{ {
return std::visit(std::forward<T>(visitor), m_data); return std::visit(std::forward<Visitor>(visitor), m_data);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename Visitor>
decltype(auto) Event::visit(T&& visitor) const decltype(auto) Event::visit(Visitor&& visitor) const
{ {
return std::visit(std::forward<T>(visitor), m_data); return std::visit(std::forward<Visitor>(visitor), m_data);
} }
} // namespace sf } // namespace sf

View File

@ -326,8 +326,8 @@ public:
/// \see `waitEvent`, `pollEvent` /// \see `waitEvent`, `pollEvent`
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename... Ts> template <typename... Handlers>
void handleEvents(Ts&&... handlers); void handleEvents(Handlers&&... handlers);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the position of the window /// \brief Get the position of the window

View File

@ -57,16 +57,17 @@ struct DelayOverloadResolution
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename... Ts> template <typename... Handlers>
void WindowBase::handleEvents(Ts&&... handlers) // NOLINT(cppcoreguidelines-missing-std-forward) void WindowBase::handleEvents(Handlers&&... handlers)
{ {
static_assert(sizeof...(Ts) > 0, "Must provide at least one handler"); static_assert(sizeof...(Handlers) > 0, "Must provide at least one handler");
// Disable misc-const-correctness for this line since clang-tidy // Disable misc-const-correctness for this line since clang-tidy
// complains about it even though the code would become uncompilable // complains about it even though the code would become incorrect
// NOLINTNEXTLINE(misc-const-correctness) // NOLINTNEXTLINE(misc-const-correctness)
priv::OverloadSet overloadSet{std::forward<Ts>(handlers)..., [](const priv::DelayOverloadResolution&) { /* ignore */ }}; priv::OverloadSet overloadSet{std::forward<Handlers>(handlers)...,
[](const priv::DelayOverloadResolution&) { /* ignore */ }};
while (std::optional event = pollEvent()) while (std::optional event = pollEvent())
event->visit(overloadSet); event->visit(overloadSet);