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 --- .clang-tidy | 2 -- src/DI/auto_wirable.hpp | 4 ++-- src/DI/auto_wirable.tpp | 4 ++-- src/DI/container.hpp | 6 +++--- src/DI/container.tpp | 6 +++--- src/DI/function_wrapper.hpp | 2 +- src/DI/function_wrapper.tpp | 2 +- src/DI/interfaces/wrapper.hpp | 2 +- src/DI/object_type.cpp | 10 +++++----- src/DI/object_type.hpp | 8 ++++---- src/DI/object_wrapper.hpp | 2 +- src/DI/object_wrapper.tpp | 2 +- src/argument_parser.cpp | 10 +++++----- src/argument_parser.hpp | 4 ++-- src/bootstrap.cpp | 2 +- src/bootstrap.hpp | 2 +- src/conversion.cpp | 2 +- src/conversion.hpp | 2 +- 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 +- src/game/game.cpp | 4 ++-- src/game/game.hpp | 4 ++-- src/game/generation_tracker.cpp | 4 ++-- src/game/generation_tracker.hpp | 4 ++-- src/game/statusline.cpp | 4 ++-- src/game/statusline.hpp | 4 ++-- src/game_of_life.cpp | 2 +- src/interfaces/argument_parser.hpp | 10 +++++----- src/interfaces/cursor.hpp | 2 +- src/interfaces/game.hpp | 4 ++-- src/interfaces/generation_tracker.hpp | 4 ++-- src/interfaces/matrix.hpp | 14 +++++++------- src/interfaces/randomization.hpp | 6 +++--- src/interfaces/scene.hpp | 4 ++-- src/interfaces/window.hpp | 2 +- src/randomization/generator.cpp | 4 ++-- src/randomization/generator.hpp | 4 ++-- src/randomization/seed_generator.cpp | 2 +- src/randomization/seed_generator.hpp | 2 +- src/util/color.cpp | 4 ++-- src/util/color.hpp | 4 ++-- 55 files changed, 169 insertions(+), 171 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 6fffdc8..5406dd0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,8 +11,6 @@ Checks: ' -bugprone-lambda-function-name, -bugprone-reserved-identifier, -google-readability-braces-around-statements, - -modernize-return-braced-init-list, - -modernize-use-trailing-return-type, -misc-non-private-member-variables-in-classes' WarningsAsErrors: '*' HeaderFilterRegex: '\/src\/' diff --git a/src/DI/auto_wirable.hpp b/src/DI/auto_wirable.hpp index 178158a..54a291e 100644 --- a/src/DI/auto_wirable.hpp +++ b/src/DI/auto_wirable.hpp @@ -8,14 +8,14 @@ template class IAutoWirable { public: - static Interface resolve() noexcept; + static auto resolve() noexcept -> Interface; }; template class AutoWirable : public IAutoWirable { public: - static std::shared_ptr resolve(const Container &container) noexcept; + static auto resolve(const Container &container) noexcept -> std::shared_ptr; }; #include "auto_wirable.tpp" diff --git a/src/DI/auto_wirable.tpp b/src/DI/auto_wirable.tpp index a99d82b..3b42cc4 100644 --- a/src/DI/auto_wirable.tpp +++ b/src/DI/auto_wirable.tpp @@ -3,8 +3,8 @@ #include "auto_wirable.hpp" template -std::shared_ptr AutoWirable::resolve( - const Container &container) noexcept +auto AutoWirable::resolve( + const Container &container) noexcept -> std::shared_ptr { return std::make_shared(container.get()...); } diff --git a/src/DI/container.hpp b/src/DI/container.hpp index 2efb265..83f24ae 100644 --- a/src/DI/container.hpp +++ b/src/DI/container.hpp @@ -32,13 +32,13 @@ public: Container() noexcept = default; template - BindingBuilder bind() noexcept; + auto bind() noexcept -> BindingBuilder; template >> - std::shared_ptr get() const noexcept; + auto get() const noexcept -> std::shared_ptr; template >> - Interface get() const noexcept; + auto get() const noexcept -> Interface; std::unordered_map, ObjectTypeHasher> bindings; diff --git a/src/DI/container.tpp b/src/DI/container.tpp index ed7f34f..2573223 100644 --- a/src/DI/container.tpp +++ b/src/DI/container.tpp @@ -32,13 +32,13 @@ void BindingBuilder::to_factory(Interface func) noexcept } template -BindingBuilder Container::bind() noexcept +auto Container::bind() noexcept -> BindingBuilder { return BindingBuilder(this); } template -std::shared_ptr Container::get() const noexcept +auto Container::get() const noexcept -> std::shared_ptr { ObjectType interface_type; @@ -57,7 +57,7 @@ std::shared_ptr Container::get() const noexcept } template -Interface Container::get() const noexcept +auto Container::get() const noexcept -> Interface { auto wrapper = std::dynamic_pointer_cast>( bindings.at(ObjectType())); diff --git a/src/DI/function_wrapper.hpp b/src/DI/function_wrapper.hpp index e6468f2..b8d0cab 100644 --- a/src/DI/function_wrapper.hpp +++ b/src/DI/function_wrapper.hpp @@ -11,7 +11,7 @@ class FunctionWrapper : public IWrapper public: explicit FunctionWrapper(Interface func) noexcept; - [[nodiscard]] Interface get() const noexcept override; + [[nodiscard]] auto get() const noexcept -> Interface override; private: const Interface _func; diff --git a/src/DI/function_wrapper.tpp b/src/DI/function_wrapper.tpp index 540a7aa..6a9c317 100644 --- a/src/DI/function_wrapper.tpp +++ b/src/DI/function_wrapper.tpp @@ -8,7 +8,7 @@ FunctionWrapper::FunctionWrapper(Interface func) noexcept : _func(fun } template -Interface FunctionWrapper::get() const noexcept +auto FunctionWrapper::get() const noexcept -> Interface { return _func; } diff --git a/src/DI/interfaces/wrapper.hpp b/src/DI/interfaces/wrapper.hpp index cde555f..e22ea7f 100644 --- a/src/DI/interfaces/wrapper.hpp +++ b/src/DI/interfaces/wrapper.hpp @@ -13,5 +13,5 @@ template class IWrapper : public IGenericWrapper { public: - [[nodiscard]] virtual Interface get() const noexcept = 0; + [[nodiscard]] virtual auto get() const noexcept -> Interface = 0; }; diff --git a/src/DI/object_type.cpp b/src/DI/object_type.cpp index 008c4a4..64a23fa 100644 --- a/src/DI/object_type.cpp +++ b/src/DI/object_type.cpp @@ -5,22 +5,22 @@ BaseObjectType::BaseObjectType(const std::type_info &type_info) noexcept { } -bool BaseObjectType::operator==(const BaseObjectType &object_type) const noexcept +auto BaseObjectType::operator==(const BaseObjectType &object_type) const noexcept -> bool { return hash() == object_type.hash(); } -std::size_t BaseObjectType::hash() const noexcept +auto BaseObjectType::hash() const noexcept -> std::size_t { return _type_info.hash_code(); } -std::string_view BaseObjectType::name() const noexcept +auto BaseObjectType::name() const noexcept -> std::string_view { - return std::string_view(_type_info.name()); + return {_type_info.name()}; } -std::size_t ObjectTypeHasher::operator()(const BaseObjectType &object_type) const noexcept +auto ObjectTypeHasher::operator()(const BaseObjectType &object_type) const noexcept -> std::size_t { return object_type.hash(); } diff --git a/src/DI/object_type.hpp b/src/DI/object_type.hpp index 6b27682..5107dbf 100644 --- a/src/DI/object_type.hpp +++ b/src/DI/object_type.hpp @@ -8,11 +8,11 @@ class BaseObjectType public: explicit BaseObjectType(const std::type_info &type_info) noexcept; - bool operator==(const BaseObjectType &object_type) const noexcept; + auto operator==(const BaseObjectType &object_type) const noexcept -> bool; - [[nodiscard]] std::size_t hash() const noexcept; + [[nodiscard]] auto hash() const noexcept -> std::size_t; - [[nodiscard]] std::string_view name() const noexcept; + [[nodiscard]] auto name() const noexcept -> std::string_view; private: const std::type_info &_type_info; @@ -28,5 +28,5 @@ public: class ObjectTypeHasher { public: - std::size_t operator()(const BaseObjectType &object_type) const noexcept; + auto operator()(const BaseObjectType &object_type) const noexcept -> std::size_t; }; diff --git a/src/DI/object_wrapper.hpp b/src/DI/object_wrapper.hpp index 4aee9af..28121cb 100644 --- a/src/DI/object_wrapper.hpp +++ b/src/DI/object_wrapper.hpp @@ -11,7 +11,7 @@ class ObjectWrapper : public IWrapper> public: explicit ObjectWrapper(const Container &container) noexcept : _container(container) {} - [[nodiscard]] std::shared_ptr get() const noexcept override; + [[nodiscard]] auto get() const noexcept -> std::shared_ptr override; private: const Container &_container; diff --git a/src/DI/object_wrapper.tpp b/src/DI/object_wrapper.tpp index bbb7bee..5334247 100644 --- a/src/DI/object_wrapper.tpp +++ b/src/DI/object_wrapper.tpp @@ -3,7 +3,7 @@ #include "object_wrapper.hpp" template -std::shared_ptr ObjectWrapper::get() const noexcept +auto ObjectWrapper::get() const noexcept -> std::shared_ptr { return ObjectImpl::resolve(_container); } diff --git a/src/argument_parser.cpp b/src/argument_parser.cpp index 94c6a4a..fd18bc7 100644 --- a/src/argument_parser.cpp +++ b/src/argument_parser.cpp @@ -19,9 +19,9 @@ void optarg_error(char arg, const std::string_view &error) noexcept /** * Returns the current optarg as a string view. */ -std::string_view get_str_optarg() noexcept +auto get_str_optarg() noexcept -> std::string_view { - return std::string_view(optarg); + return {optarg}; } /** @@ -30,7 +30,7 @@ std::string_view get_str_optarg() noexcept * @param arg The current command-line argument character * @param check_zero Whether or not to make sure that the result is not zero */ -uint32_t get_uint_optarg(char arg, bool check_zero = false) noexcept +auto get_uint_optarg(char arg, bool check_zero = false) noexcept -> uint32_t { auto conversion_result = str_to_uint(get_str_optarg()); @@ -49,10 +49,10 @@ ArgumentParser::ArgumentParser( { } -ParsedArguments ArgumentParser::parse( +auto ArgumentParser::parse( const std::vector