From a039c8ad36779903571419cb06cd052f8fc41512 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 29 Mar 2022 17:40:04 +0200 Subject: refactor: use trailing return types --- src/engine/data/bounds.cpp | 14 +++++++------- src/engine/data/bounds.hpp | 14 +++++++------- src/engine/data/vector2.cpp | 22 +++++++++++----------- src/engine/data/vector2.hpp | 30 +++++++++++++++--------------- src/engine/graphics/matrix.hpp | 14 +++++++------- src/engine/graphics/matrix.tpp | 14 +++++++------- src/engine/graphics/scene.cpp | 2 +- src/engine/graphics/scene.hpp | 4 ++-- src/engine/graphics/window.cpp | 2 +- src/engine/graphics/window.hpp | 2 +- src/engine/matrix_iterator.hpp | 24 ++++++++++++------------ src/engine/matrix_iterator.tpp | 24 ++++++++++++------------ src/engine/user/cursor.cpp | 2 +- src/engine/user/cursor.hpp | 2 +- src/engine/user/input.cpp | 4 ++-- src/engine/user/input.hpp | 2 +- 16 files changed, 88 insertions(+), 88 deletions(-) (limited to 'src/engine') diff --git a/src/engine/data/bounds.cpp b/src/engine/data/bounds.cpp index 1a8c4d0..ca67008 100644 --- a/src/engine/data/bounds.cpp +++ b/src/engine/data/bounds.cpp @@ -5,7 +5,7 @@ Bounds::Bounds(const BoundsOptions &options) noexcept { } -Bounds::Value Bounds::get_width() const noexcept +auto Bounds::get_width() const noexcept -> Bounds::Value { return _width; } @@ -15,7 +15,7 @@ void Bounds::set_width(Bounds::Value width) noexcept _width = width; } -Bounds::Value Bounds::get_height() const noexcept +auto Bounds::get_height() const noexcept -> Bounds::Value { return _height; } @@ -25,7 +25,7 @@ void Bounds::set_height(Bounds::Value height) noexcept _height = height; } -CoordsValidation Bounds::validate_coords(const Vector2 &coords) const noexcept +auto Bounds::validate_coords(const Vector2 &coords) const noexcept -> CoordsValidation { if (static_cast(coords.get_x()) >= _width) { @@ -50,7 +50,7 @@ CoordsValidation Bounds::validate_coords(const Vector2 &coords) const noexcept return CoordsValidation::VALID; } -const Bounds &Bounds::operator*=(const Bounds &rhs) noexcept +auto Bounds::operator*=(const Bounds &rhs) noexcept -> const Bounds & { _width *= rhs._width; _height *= rhs._height; @@ -58,7 +58,7 @@ const Bounds &Bounds::operator*=(const Bounds &rhs) noexcept return *this; } -const Bounds &Bounds::operator+=(const Bounds &rhs) noexcept +auto Bounds::operator+=(const Bounds &rhs) noexcept -> const Bounds & { _width += rhs._width; _height += rhs._height; @@ -66,7 +66,7 @@ const Bounds &Bounds::operator+=(const Bounds &rhs) noexcept return *this; } -const Bounds &Bounds::operator-=(const Bounds &rhs) noexcept +auto Bounds::operator-=(const Bounds &rhs) noexcept -> const Bounds & { _width -= rhs._width; _height -= rhs._height; @@ -74,7 +74,7 @@ const Bounds &Bounds::operator-=(const Bounds &rhs) noexcept return *this; } -Bounds Bounds::operator-(const Bounds &rhs) const noexcept +auto Bounds::operator-(const Bounds &rhs) const noexcept -> Bounds { auto new_bounds = Bounds(*this); diff --git a/src/engine/data/bounds.hpp b/src/engine/data/bounds.hpp index ccea2c3..5444503 100644 --- a/src/engine/data/bounds.hpp +++ b/src/engine/data/bounds.hpp @@ -26,21 +26,21 @@ public: explicit Bounds(const BoundsOptions &options) noexcept; - [[nodiscard]] Value get_width() const noexcept; + [[nodiscard]] auto get_width() const noexcept -> Value; void set_width(Value width) noexcept; - [[nodiscard]] Value get_height() const noexcept; + [[nodiscard]] auto get_height() const noexcept -> Value; void set_height(Value height) noexcept; - [[nodiscard]] CoordsValidation validate_coords(const Vector2 &coords) const noexcept; + [[nodiscard]] auto validate_coords(const Vector2 &coords) const noexcept -> CoordsValidation; - const Bounds &operator*=(const Bounds &rhs) noexcept; - const Bounds &operator+=(const Bounds &rhs) noexcept; - const Bounds &operator-=(const Bounds &rhs) noexcept; + auto operator*=(const Bounds &rhs) noexcept -> const Bounds &; + auto operator+=(const Bounds &rhs) noexcept -> const Bounds &; + auto operator-=(const Bounds &rhs) noexcept -> const Bounds &; - Bounds operator-(const Bounds &rhs) const noexcept; + auto operator-(const Bounds &rhs) const noexcept -> Bounds; private: Value _width = 0U; diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp index b838051..0554930 100644 --- a/src/engine/data/vector2.cpp +++ b/src/engine/data/vector2.cpp @@ -2,7 +2,7 @@ #include "util/hash.hpp" -Vector2::Value Vector2::get_x() const noexcept +auto Vector2::get_x() const noexcept -> Vector2::Value { return _x; } @@ -12,7 +12,7 @@ void Vector2::set_x(Vector2::Value x) noexcept _x = x; } -Vector2::Value Vector2::get_y() const noexcept +auto Vector2::get_y() const noexcept -> Vector2::Value { return _y; } @@ -22,13 +22,13 @@ void Vector2::set_y(Vector2::Value y) noexcept _y = y; } -Vector2 Vector2::to_direction(const Vector2 &direction, - Vector2::Value amount) const noexcept +auto Vector2::to_direction(const Vector2 &direction, + Vector2::Value amount) const noexcept -> Vector2 { return *this + (direction * Vector2({.x = amount, .y = amount})); } -const Vector2 &Vector2::operator+=(const Vector2 &rhs) noexcept +auto Vector2::operator+=(const Vector2 &rhs) noexcept -> const Vector2 & { _x += rhs._x; _y += rhs._y; @@ -36,7 +36,7 @@ const Vector2 &Vector2::operator+=(const Vector2 &rhs) noexcept return *this; } -const Vector2 &Vector2::operator-=(const Vector2 &rhs) noexcept +auto Vector2::operator-=(const Vector2 &rhs) noexcept -> const Vector2 & { _x -= rhs._x; _y -= rhs._y; @@ -44,7 +44,7 @@ const Vector2 &Vector2::operator-=(const Vector2 &rhs) noexcept return *this; } -Vector2 Vector2::operator+(const Vector2 &rhs) const noexcept +auto Vector2::operator+(const Vector2 &rhs) const noexcept -> Vector2 { auto new_vector2 = Vector2(*this); @@ -54,7 +54,7 @@ Vector2 Vector2::operator+(const Vector2 &rhs) const noexcept return new_vector2; } -Vector2 Vector2::operator-(const Vector2 &rhs) const noexcept +auto Vector2::operator-(const Vector2 &rhs) const noexcept -> Vector2 { auto new_vector2 = Vector2(*this); @@ -64,7 +64,7 @@ Vector2 Vector2::operator-(const Vector2 &rhs) const noexcept return new_vector2; } -Vector2 Vector2::operator*(const Vector2 &rhs) const noexcept +auto Vector2::operator*(const Vector2 &rhs) const noexcept -> Vector2 { auto new_vector2 = *this; @@ -74,12 +74,12 @@ Vector2 Vector2::operator*(const Vector2 &rhs) const noexcept return new_vector2; } -bool Vector2::operator==(const Vector2 &rhs) const noexcept +auto Vector2::operator==(const Vector2 &rhs) const noexcept -> bool { return _x == rhs._x && _y == rhs._y; } -std::size_t Vector2Hasher::operator()(const Vector2 &vector2) const noexcept +auto Vector2Hasher::operator()(const Vector2 &vector2) const noexcept -> std::size_t { std::size_t result_hash = 0; diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp index 78eba11..95baf1c 100644 --- a/src/engine/data/vector2.hpp +++ b/src/engine/data/vector2.hpp @@ -22,30 +22,30 @@ public: { } - [[nodiscard]] Value get_x() const noexcept; + [[nodiscard]] auto get_x() const noexcept -> Value; void set_x(Value x) noexcept; - [[nodiscard]] Value get_y() const noexcept; + [[nodiscard]] auto get_y() const noexcept -> Value; void set_y(Value y) noexcept; - [[nodiscard]] Vector2 to_direction(const Vector2 &direction, - Vector2::Value amount) const noexcept; + [[nodiscard]] auto to_direction(const Vector2 &direction, + Vector2::Value amount) const noexcept -> Vector2; - const Vector2 &operator+=(const Vector2 &rhs) noexcept; - const Vector2 &operator-=(const Vector2 &rhs) noexcept; + auto operator+=(const Vector2 &rhs) noexcept -> const Vector2 &; + auto operator-=(const Vector2 &rhs) noexcept -> const Vector2 &; - Vector2 operator+(const Vector2 &rhs) const noexcept; - Vector2 operator-(const Vector2 &rhs) const noexcept; - Vector2 operator*(const Vector2 &rhs) const noexcept; + auto operator+(const Vector2 &rhs) const noexcept -> Vector2; + auto operator-(const Vector2 &rhs) const noexcept -> Vector2; + auto operator*(const Vector2 &rhs) const noexcept -> Vector2; - bool operator==(const Vector2 &rhs) const noexcept; + auto operator==(const Vector2 &rhs) const noexcept -> bool; /** * Returns Vector2({.x = 0, .y = -1}) */ - static constexpr Vector2 up() noexcept + static constexpr auto up() noexcept -> Vector2 { return Vector2({.x = 0, .y = -1}); } @@ -53,7 +53,7 @@ public: /** * Returns Vector2({.x = 0, .y = 1}) */ - static constexpr Vector2 down() noexcept + static constexpr auto down() noexcept -> Vector2 { return Vector2({.x = 0, .y = 1}); } @@ -61,7 +61,7 @@ public: /** * Returns Vector2({.x = -1, .y = 0}) */ - static constexpr Vector2 left() noexcept + static constexpr auto left() noexcept -> Vector2 { return Vector2({.x = -1, .y = 0}); @@ -70,7 +70,7 @@ public: /** * Returns Vector2({.x = 1, .y = 0}) */ - static constexpr Vector2 right() noexcept + static constexpr auto right() noexcept -> Vector2 { return Vector2({.x = 1, .y = 0}); } @@ -83,5 +83,5 @@ private: class Vector2Hasher { public: - std::size_t operator()(const Vector2 &vector2) const noexcept; + auto operator()(const Vector2 &vector2) const noexcept -> std::size_t; }; diff --git a/src/engine/graphics/matrix.hpp b/src/engine/graphics/matrix.hpp index 2c9ba81..f71018b 100644 --- a/src/engine/graphics/matrix.hpp +++ b/src/engine/graphics/matrix.hpp @@ -23,21 +23,21 @@ public: void fill(Element element) noexcept override; - [[nodiscard]] Element get(const Vector2 &pos) const noexcept override; + [[nodiscard]] auto get(const Vector2 &pos) const noexcept -> Element override; void set(const Vector2 &pos, Element element) noexcept override; - [[nodiscard]] uint32_t get_row_cnt() const noexcept override; + [[nodiscard]] auto get_row_cnt() const noexcept -> uint32_t override; - [[nodiscard]] uint32_t get_column_cnt() const noexcept override; + [[nodiscard]] auto get_column_cnt() const noexcept -> uint32_t override; - [[nodiscard]] MatrixIterator begin() const noexcept override; + [[nodiscard]] auto begin() const noexcept -> MatrixIterator override; - [[nodiscard]] MatrixIterator end() const noexcept override; + [[nodiscard]] auto end() const noexcept -> MatrixIterator override; - Matrix &operator=(const Matrix &rhs) noexcept; + auto operator=(const Matrix &rhs) noexcept -> Matrix &; - Matrix &operator=(Matrix &&rhs) noexcept; + auto operator=(Matrix &&rhs) noexcept -> Matrix &; private: gsl::owner _matrix; diff --git a/src/engine/graphics/matrix.tpp b/src/engine/graphics/matrix.tpp index e0e65bb..527c61f 100644 --- a/src/engine/graphics/matrix.tpp +++ b/src/engine/graphics/matrix.tpp @@ -49,7 +49,7 @@ void Matrix::fill(Element element) noexcept } template -Element Matrix::get(const Vector2 &pos) const noexcept +auto Matrix::get(const Vector2 &pos) const noexcept -> Element { auto x = static_cast(pos.get_x()); @@ -70,31 +70,31 @@ void Matrix::set(const Vector2 &pos, Element element) noexcept } template -uint32_t Matrix::get_row_cnt() const noexcept +auto Matrix::get_row_cnt() const noexcept -> uint32_t { return _row_cnt; } template -uint32_t Matrix::get_column_cnt() const noexcept +auto Matrix::get_column_cnt() const noexcept -> uint32_t { return _column_cnt; } template -MatrixIterator Matrix::begin() const noexcept +auto Matrix::begin() const noexcept -> MatrixIterator { return MatrixIterator(_matrix, _column_cnt); } template -MatrixIterator Matrix::end() const noexcept +auto Matrix::end() const noexcept -> MatrixIterator { return MatrixIterator(_matrix + _row_cnt, _column_cnt); } template -Matrix &Matrix::operator=(const Matrix &rhs) noexcept +auto Matrix::operator=(const Matrix &rhs) noexcept -> Matrix & { if (&rhs != this) { @@ -111,7 +111,7 @@ Matrix &Matrix::operator=(const Matrix &rhs) noexcept } template -Matrix &Matrix::operator=(Matrix &&rhs) noexcept +auto Matrix::operator=(Matrix &&rhs) noexcept -> Matrix & { if (&rhs != this) { diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index 24c174f..c27a6d5 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -45,7 +45,7 @@ void Scene::leave() noexcept _is_shown = false; } -const std::shared_ptr> &Scene::get_matrix() const noexcept +auto Scene::get_matrix() const noexcept -> const std::shared_ptr> & { return _matrix; } diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index c4f6d67..3dcaa2d 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -23,8 +23,8 @@ public: void leave() noexcept override; - [[nodiscard]] const std::shared_ptr> & - get_matrix() const noexcept override; + [[nodiscard]] auto + get_matrix() const noexcept -> const std::shared_ptr> & override; private: bool _is_shown; diff --git a/src/engine/graphics/window.cpp b/src/engine/graphics/window.cpp index d6bae0c..bb33402 100644 --- a/src/engine/graphics/window.cpp +++ b/src/engine/graphics/window.cpp @@ -2,7 +2,7 @@ #include -Bounds Window::size() const noexcept +auto Window::size() const noexcept -> Bounds { winsize window_size = {}; diff --git a/src/engine/graphics/window.hpp b/src/engine/graphics/window.hpp index c9a9c70..69c04c3 100644 --- a/src/engine/graphics/window.hpp +++ b/src/engine/graphics/window.hpp @@ -10,5 +10,5 @@ class Window : public IWindow, public AutoWirable public: Window() noexcept = default; - [[nodiscard]] Bounds size() const noexcept override; + [[nodiscard]] auto size() const noexcept -> Bounds override; }; diff --git a/src/engine/matrix_iterator.hpp b/src/engine/matrix_iterator.hpp index 5d35052..674216f 100644 --- a/src/engine/matrix_iterator.hpp +++ b/src/engine/matrix_iterator.hpp @@ -10,13 +10,13 @@ public: explicit MatrixRowIterator(ColumnPtr column_ptr) noexcept; - MatrixRowIterator &operator++() noexcept; - MatrixRowIterator operator++(int) noexcept; + auto operator++() noexcept -> MatrixRowIterator &; + auto operator++(int) noexcept -> MatrixRowIterator; - Element &operator*() const noexcept; + auto operator*() const noexcept -> Element &; - bool operator==(const MatrixRowIterator &rhs) const noexcept; - bool operator!=(const MatrixRowIterator &rhs) const noexcept; + auto operator==(const MatrixRowIterator &rhs) const noexcept -> bool; + auto operator!=(const MatrixRowIterator &rhs) const noexcept -> bool; private: ColumnPtr _column_ptr; @@ -30,9 +30,9 @@ public: explicit MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; - [[nodiscard]] MatrixRowIterator begin() const noexcept; + [[nodiscard]] auto begin() const noexcept -> MatrixRowIterator; - [[nodiscard]] MatrixRowIterator end() const noexcept; + [[nodiscard]] auto end() const noexcept -> MatrixRowIterator; private: RowPtr _row_ptr; @@ -48,13 +48,13 @@ public: explicit MatrixIterator(RowPtr row_ptr, const uint32_t &column_cnt) noexcept; - MatrixIterator &operator++() noexcept; - MatrixIterator operator++(int) noexcept; + auto operator++() noexcept -> MatrixIterator &; + auto operator++(int) noexcept -> MatrixIterator; - MatrixRow operator*() const noexcept; + auto operator*() const noexcept -> MatrixRow; - bool operator==(const MatrixIterator &rhs) const noexcept; - bool operator!=(const MatrixIterator &rhs) const noexcept; + auto operator==(const MatrixIterator &rhs) const noexcept -> bool; + auto operator!=(const MatrixIterator &rhs) const noexcept -> bool; private: RowPtr _row_ptr; diff --git a/src/engine/matrix_iterator.tpp b/src/engine/matrix_iterator.tpp index 52952c9..031136c 100644 --- a/src/engine/matrix_iterator.tpp +++ b/src/engine/matrix_iterator.tpp @@ -11,7 +11,7 @@ MatrixRowIterator::MatrixRowIterator(ColumnPtr column_ptr) noexcept } template -MatrixRowIterator &MatrixRowIterator::operator++() noexcept +auto MatrixRowIterator::operator++() noexcept -> MatrixRowIterator & { ++_column_ptr; @@ -19,7 +19,7 @@ MatrixRowIterator &MatrixRowIterator::operator++() noexcept } template -MatrixRowIterator MatrixRowIterator::operator++(int) noexcept +auto MatrixRowIterator::operator++(int) noexcept -> MatrixRowIterator { auto copy = *this; @@ -29,19 +29,19 @@ MatrixRowIterator MatrixRowIterator::operator++(int) noexcept } template -Element &MatrixRowIterator::operator*() const noexcept +auto MatrixRowIterator::operator*() const noexcept -> Element & { return *_column_ptr; } template -bool MatrixRowIterator::operator==(const MatrixRowIterator &rhs) const noexcept +auto MatrixRowIterator::operator==(const MatrixRowIterator &rhs) const noexcept -> bool { return _column_ptr == rhs._column_ptr; } template -bool MatrixRowIterator::operator!=(const MatrixRowIterator &rhs) const noexcept +auto MatrixRowIterator::operator!=(const MatrixRowIterator &rhs) const noexcept -> bool { return _column_ptr != rhs._column_ptr; } @@ -55,13 +55,13 @@ MatrixRow::MatrixRow(RowPtr row_ptr, const uint32_t &column_cnt) noexce } template -MatrixRowIterator MatrixRow::begin() const noexcept +auto MatrixRow::begin() const noexcept -> MatrixRowIterator { return MatrixRowIterator(_row_ptr); } template -MatrixRowIterator MatrixRow::end() const noexcept +auto MatrixRow::end() const noexcept -> MatrixRowIterator { return MatrixRowIterator(_row_ptr + _column_cnt); } @@ -76,7 +76,7 @@ MatrixIterator::MatrixIterator(RowPtr row_ptr, } template -MatrixIterator &MatrixIterator::operator++() noexcept +auto MatrixIterator::operator++() noexcept -> MatrixIterator & { ++_row_ptr; @@ -84,7 +84,7 @@ MatrixIterator &MatrixIterator::operator++() noexcept } template -MatrixIterator MatrixIterator::operator++(int) noexcept +auto MatrixIterator::operator++(int) noexcept -> MatrixIterator { auto copy = *this; @@ -94,19 +94,19 @@ MatrixIterator MatrixIterator::operator++(int) noexcept } template -MatrixRow MatrixIterator::operator*() const noexcept +auto MatrixIterator::operator*() const noexcept -> MatrixRow { return MatrixRow(*_row_ptr, _column_cnt); } template -bool MatrixIterator::operator==(const MatrixIterator &rhs) const noexcept +auto MatrixIterator::operator==(const MatrixIterator &rhs) const noexcept -> bool { return _row_ptr == rhs._row_ptr; } template -bool MatrixIterator::operator!=(const MatrixIterator &rhs) const noexcept +auto MatrixIterator::operator!=(const MatrixIterator &rhs) const noexcept -> bool { return _row_ptr != rhs._row_ptr; } diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp index 2a72663..2b240b9 100644 --- a/src/engine/user/cursor.cpp +++ b/src/engine/user/cursor.cpp @@ -34,7 +34,7 @@ void CursorController::move_to(const Vector2 &position, bool silent) noexcept } } -Vector2 CursorController::where() const noexcept +auto CursorController::where() const noexcept -> Vector2 { return _position; } diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index fd75374..ccdf71a 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -39,7 +39,7 @@ public: void move_to(const Vector2 &position, bool silent) noexcept override; - [[nodiscard]] Vector2 where() const noexcept override; + [[nodiscard]] auto where() const noexcept -> Vector2 override; void ensure_position() noexcept override; diff --git a/src/engine/user/input.cpp b/src/engine/user/input.cpp index 81fe2f6..87d8a68 100644 --- a/src/engine/user/input.cpp +++ b/src/engine/user/input.cpp @@ -60,8 +60,8 @@ void InputHandler::leave_raw_mode() noexcept _original_termios = nullptr; } -InputHandler::_SubscribersSizeType -InputHandler::_event_as_index(const Event &event) noexcept +auto +InputHandler::_event_as_index(const Event &event) noexcept -> InputHandler::_SubscribersSizeType { return static_cast<_SubscribersSizeType>(static_cast(event)); } diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp index f86d0d0..0a437ef 100644 --- a/src/engine/user/input.hpp +++ b/src/engine/user/input.hpp @@ -36,5 +36,5 @@ private: using _SubscribersSizeType = decltype(_subscribers)::size_type; - static _SubscribersSizeType _event_as_index(const Event &event) noexcept; + static auto _event_as_index(const Event &event) noexcept -> _SubscribersSizeType; }; -- cgit v1.2.3-18-g5258