From 08ffc28f67523d72728dd222a98e72c273991700 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 7 Sep 2024 22:14:19 +0200 Subject: [PATCH] Apply clang-format Llvm on C++ code --- .clang-format | 48 +++++----- chapter01/policy_example/src/main.cpp | 5 +- chapter01/simple_executable/src/main.cpp | 7 +- .../framework/components/component1.hpp | 48 +++++----- chapter02/component1/src/component1.cpp | 26 ++---- .../framework/components/component2.hpp | 48 +++++----- chapter02/component2/src/component2.cpp | 26 ++---- .../components/component_interface.hpp | 40 ++++----- chapter02/driver_app/src/main.cpp | 39 ++++---- chapter02/simple_example/src/main.cpp | 7 +- .../hello_header_only/hello_header_only.hpp | 7 +- .../include/hello_object/hello_object.hpp | 9 +- .../hello_object_lib/src/hello_object.cpp | 5 +- .../hello_shared_lib/include/hello/hello.hpp | 11 +-- chapter03/hello_shared_lib/src/hello.cpp | 7 +- chapter03/hello_shared_lib/src/internal.cpp | 7 +- .../include/hello/hello.hpp | 11 +-- .../src/hello.cpp | 7 +- .../src/internal.cpp | 7 +- .../hello_static_lib/include/hello/hello.hpp | 11 +-- chapter03/hello_static_lib/src/hello.cpp | 7 +- chapter03/hello_static_lib/src/internal.cpp | 7 +- chapter03/hello_world_standalone/src/main.cpp | 5 +- chapter03/src/main.cpp | 11 ++- chapter04/ex01_executable/src/main.cpp | 5 +- .../ex02_static/include/chapter4/ex02/lib.hpp | 14 ++- chapter04/ex02_static/src/lib.cpp | 11 +-- .../include/chapter4/ex05/lib.hpp | 14 ++- .../ex05_config_file_package/src/lib.cpp | 11 +-- chapter04/ex05_consumer/src/main.cpp | 7 +- chapter04/ex06_pack/executable/src/main.cpp | 7 +- .../library/include/chapter4/ex06/lib.hpp | 8 +- chapter04/ex06_pack/library/src/lib.cpp | 5 +- .../executable/src/main.cpp | 7 +- .../library/include/chapter4/ex07/lib.hpp | 8 +- .../library/src/lib.cpp | 5 +- chapter05/CMakeLists.txt | 5 +- chapter05/conan_example/src/main.cpp | 5 +- chapter05/external_project/CMakeLists.txt | 2 +- chapter05/external_project/src/main.cpp | 7 +- chapter05/fetch_content_example/src/main.cpp | 11 +-- .../dep/include/obscure/obscure.hpp | 11 +-- chapter05/find_module/dep/src/internal.cpp | 7 +- chapter05/find_module/dep/src/obscure.cpp | 7 +- chapter05/find_module/src/main.cpp | 7 +- chapter05/find_package_example/src/main.cpp | 74 ++++++++------- chapter05/vcpkg_example/src/main.cpp | 17 ++-- .../include/chapter6/ex01/calculator.hpp | 89 +++++++++---------- .../chapter6/ex01/calculator_interface.hpp | 89 +++++++++---------- chapter06/ex01_doxdocgen/src/calculator.cpp | 26 +++--- chapter06/ex01_doxdocgen/src/main.cpp | 15 ++-- chapter06/ex02_doxplantuml/src/main.cpp | 13 ++- chapter07/clang_tidy_example/src/main.cpp | 13 ++- .../src/coverage_example/coverage_example.cpp | 31 ++++--- .../coverage_example/src/coverage_test.cpp | 15 ++-- chapter07/cppcheck_example/src/main.cpp | 11 ++- chapter07/cpplint_example/src/main.cpp | 11 ++- .../src/coverage_example/coverage_example.cpp | 31 ++++--- .../custom_build_type/src/coverage_test.cpp | 15 ++-- chapter07/fixture_example/src/main.cpp | 6 +- chapter07/fixture_example/src/server.cpp | 15 ++-- chapter07/iwyu_example/src/main.cpp | 7 +- chapter07/lwyu_example/src/main.cpp | 7 +- chapter07/pass_fail_criteria/src/main.cpp | 19 ++-- chapter07/resource_group_example/src/main.cpp | 9 +- .../simple_sanitizer_example/src/main.cpp | 11 ++- chapter07/simple_test/src/main.cpp | 6 +- chapter07/test_discovery_example/src/test.cpp | 25 ++---- chapter07/test_labels/src/main.cpp | 6 +- chapter07/timeout_example/src/main.cpp | 9 +- .../src/main.cpp | 7 +- chapter08/configure_file_example/src/main.cpp | 7 +- chapter08/custom_command_example/src/main.cpp | 7 +- .../src/main.cpp | 7 +- .../execute_process_example/src/main.cpp | 7 +- .../ex01_external_deps/src/benchmarks.cpp | 11 ++- chapter10/ex01_external_deps/src/tests.cpp | 5 +- .../src/tests.cpp | 16 ++-- chapter10/ex03_simple_qt_app/main.cpp | 13 ++- .../framework_example/include/hello/hello.hpp | 9 +- chapter11/framework_example/src/hello.cpp | 7 +- chapter11/framework_example/src/internal.cpp | 7 +- .../android-example/include/hello/hello.hpp | 11 +-- chapter12/android-example/src/hello.cpp | 7 +- chapter12/android-example/src/internal.cpp | 7 +- chapter12/check_push_pop/include/hello.hpp | 5 +- chapter12/emulator-example/src/main.cpp | 7 +- chapter12/iOS_example/include/hello/hello.hpp | 11 +-- chapter12/iOS_example/src/hello.cpp | 7 +- chapter12/iOS_example/src/internal.cpp | 7 +- .../test-executable/test.cpp | 6 +- .../ex03_external_cmake_module/src/main.cpp | 5 +- .../precompiled_headers/src/eratosthenes.cpp | 25 +++--- .../precompiled_headers/src/fibonacci.cpp | 5 +- chapter14/precompiled_headers/src/main.cpp | 19 ++-- chapter14/unity_build/src/eratosthenes.cpp | 25 +++--- chapter14/unity_build/src/fibonacci.cpp | 5 +- chapter14/unity_build/src/main.cpp | 19 ++-- .../unity_build_group/src/eratosthenes.cpp | 25 +++--- chapter14/unity_build_group/src/fibonacci.cpp | 5 +- chapter14/unity_build_group/src/main.cpp | 19 ++-- 101 files changed, 637 insertions(+), 826 deletions(-) diff --git a/.clang-format b/.clang-format index 75297fc..ede5642 100644 --- a/.clang-format +++ b/.clang-format @@ -4,23 +4,31 @@ IndentWidth: 4 UseTab: Never --- Language: Cpp -BasedOnStyle: WebKit -# XXX ColumnLimit: 123 -AccessModifierOffset: -4 -AllowShortIfStatementsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Inline -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -DerivePointerAlignment: false -IndentWidth: 4 -InsertBraces: true -InsertNewlineAtEOF: true -NamespaceIndentation: None -PointerAlignment: Right -SpacesBeforeTrailingComments: 1 -UseTab: Never -# -AlignTrailingComments: - # XXX Kind: Never - Kind: Always - OverEmptyLines: 1 +BasedOnStyle: Llvm + +# ColumnLimit: 80 +# AccessModifierOffset: -2 +# AllowShortIfStatementsOnASingleLine: false +# AllowShortFunctionsOnASingleLine: Inline +# ConstructorInitializerIndentWidth: 4 +# ContinuationIndentWidth: 4 +# DerivePointerAlignment: false +# # +# # TODO: TBD 4 instead of 2? CK +# # XXX IndentWidth: 4 +# InsertBraces: true +# InsertNewlineAtEOF: true +# NamespaceIndentation: None +# PointerAlignment: Right +# SpacesBeforeTrailingComments: 1 +# UseTab: Never + +# TODO: TBD Keep original style? CK +# AlignTrailingComments: +# Kind: Always +# OverEmptyLines: 0 + +# TODO: TBD Keep original style? CK +# BreakBeforeBraces: Custom +# BraceWrapping: +# AfterNamespace: true diff --git a/chapter01/policy_example/src/main.cpp b/chapter01/policy_example/src/main.cpp index 39de281..cf0e2bd 100644 --- a/chapter01/policy_example/src/main.cpp +++ b/chapter01/policy_example/src/main.cpp @@ -1,4 +1 @@ -int main(int, char **) -{ - return 0; -} +int main(int, char **) { return 0; } diff --git a/chapter01/simple_executable/src/main.cpp b/chapter01/simple_executable/src/main.cpp index 0fec95b..0ad1424 100644 --- a/chapter01/simple_executable/src/main.cpp +++ b/chapter01/simple_executable/src/main.cpp @@ -1,7 +1,6 @@ #include -int main(int, char **) -{ - std::cout << "Welcome to CMake Best Practices\n"; - return 0; +int main(int, char **) { + std::cout << "Welcome to CMake Best Practices\n"; + return 0; } diff --git a/chapter02/component1/include/framework/components/component1.hpp b/chapter02/component1/include/framework/components/component1.hpp index 1f060bf..42f5e95 100644 --- a/chapter02/component1/include/framework/components/component1.hpp +++ b/chapter02/component1/include/framework/components/component1.hpp @@ -10,38 +10,36 @@ #include -namespace framework { -namespace components { +namespace framework::components { /** * @brief Component 1 interface */ class component1 : public component_interface { public: - /** - * @brief Construct a new component1 object - */ - component1(); + /** + * @brief Construct a new component1 object + */ + component1(); - /** - * @brief Destroy the component1 object - */ - virtual ~component1() override; + /** + * @brief Destroy the component1 object + */ + virtual ~component1() override; - /** - * @brief Do some work - * - * @return true on success, false on failure - */ - virtual bool do_stuff() const override; + /** + * @brief Do some work + * + * @return true on success, false on failure + */ + virtual bool do_stuff() const override; - /** - * @brief Do other stuff - * - * @param param Argument - * @return int Stuffs completed - */ - virtual int do_other_stuff(int param) override; + /** + * @brief Do other stuff + * + * @param param Argument + * @return int Stuffs completed + */ + virtual int do_other_stuff(int param) override; }; // class component1 -} // namespace components -} // namespace framework +} // namespace framework::components diff --git a/chapter02/component1/src/component1.cpp b/chapter02/component1/src/component1.cpp index 79f5e8e..9570b12 100644 --- a/chapter02/component1/src/component1.cpp +++ b/chapter02/component1/src/component1.cpp @@ -10,27 +10,17 @@ #include -namespace framework { -namespace components { +namespace framework::components { -component1::component1() -{ - std::cout << "Component 1 is constructed" << std::endl; +component1::component1() { + std::cout << "Component 1 is constructed" << std::endl; } -component1::~component1() -{ - std::cout << "Component 1 is destructed" << std::endl; +component1::~component1() { + std::cout << "Component 1 is destructed" << std::endl; } -bool component1::do_stuff() const -{ - return false; -} +bool component1::do_stuff() const { return false; } -int component1::do_other_stuff(int param) -{ - return param; -} -} // namespace components -} // namespace framework +int component1::do_other_stuff(int param) { return param; } +} // namespace framework::components diff --git a/chapter02/component2/include/framework/components/component2.hpp b/chapter02/component2/include/framework/components/component2.hpp index 2ab323e..3230f66 100644 --- a/chapter02/component2/include/framework/components/component2.hpp +++ b/chapter02/component2/include/framework/components/component2.hpp @@ -10,38 +10,36 @@ #include -namespace framework { -namespace components { +namespace framework::components { /** * @brief Component 1 interface */ class component2 : public component_interface { public: - /** - * @brief Construct a new component1 object - */ - component2(); + /** + * @brief Construct a new component1 object + */ + component2(); - /** - * @brief Destroy the component1 object - */ - virtual ~component2() override; + /** + * @brief Destroy the component1 object + */ + virtual ~component2() override; - /** - * @brief Do some work - * - * @return true on success, false on failure - */ - virtual bool do_stuff() const override; + /** + * @brief Do some work + * + * @return true on success, false on failure + */ + virtual bool do_stuff() const override; - /** - * @brief Do other stuff - * - * @param param Argument - * @return int Stuffs completed - */ - virtual int do_other_stuff(int param) override; + /** + * @brief Do other stuff + * + * @param param Argument + * @return int Stuffs completed + */ + virtual int do_other_stuff(int param) override; }; // class component2 -} // namespace components -} // namespace framework +} // namespace framework::components diff --git a/chapter02/component2/src/component2.cpp b/chapter02/component2/src/component2.cpp index fa68dd4..0149fd4 100644 --- a/chapter02/component2/src/component2.cpp +++ b/chapter02/component2/src/component2.cpp @@ -11,27 +11,17 @@ #include #include -namespace framework { -namespace components { +namespace framework::components { -component2::component2() -{ - std::cout << "Component 2 is constructed" << std::endl; +component2::component2() { + std::cout << "Component 2 is constructed" << std::endl; } -component2::~component2() -{ - std::cout << "Component 2 is destructed" << std::endl; +component2::~component2() { + std::cout << "Component 2 is destructed" << std::endl; } -bool component2::do_stuff() const -{ - return true; -} +bool component2::do_stuff() const { return true; } -int component2::do_other_stuff(int param) -{ - return std::sqrt(param) * 2; -} -} // namespace components -} // namespace framework +int component2::do_other_stuff(int param) { return std::sqrt(param) * 2; } +} // namespace framework::components diff --git a/chapter02/component_interface/include/framework/components/component_interface.hpp b/chapter02/component_interface/include/framework/components/component_interface.hpp index 69b9f5d..e08156b 100644 --- a/chapter02/component_interface/include/framework/components/component_interface.hpp +++ b/chapter02/component_interface/include/framework/components/component_interface.hpp @@ -8,32 +8,30 @@ #pragma once -namespace framework { -namespace components { +namespace framework::components { /** * @brief Component interface */ class component_interface { public: - /** - * @brief Destroy the component1 object - */ - virtual ~component_interface() = default; + /** + * @brief Destroy the component1 object + */ + virtual ~component_interface() = default; - /** - * @brief Do some work - * - * @return true on success, false on failure - */ - virtual bool do_stuff() const = 0; + /** + * @brief Do some work + * + * @return true on success, false on failure + */ + virtual bool do_stuff() const = 0; - /** - * @brief Do other stuff - * - * @param param Argument - * @return int Stuffs completed - */ - virtual int do_other_stuff(int param) = 0; + /** + * @brief Do other stuff + * + * @param param Argument + * @return int Stuffs completed + */ + virtual int do_other_stuff(int param) = 0; }; // class component_interface -} // namespace components -} // namespace framework +} // namespace framework::components diff --git a/chapter02/driver_app/src/main.cpp b/chapter02/driver_app/src/main.cpp index 33aee57..f706694 100644 --- a/chapter02/driver_app/src/main.cpp +++ b/chapter02/driver_app/src/main.cpp @@ -17,8 +17,7 @@ /** * @brief Component type */ -enum class component_type : std::uint8_t { component1, - component2 }; +enum class component_type : std::uint8_t { component1, component2 }; /** * @brief Make component @@ -30,17 +29,16 @@ enum class component_type : std::uint8_t { component1, * throws. */ std::unique_ptr -component_factory(component_type ct) noexcept(false) -{ - switch (ct) { - case component_type::component1: - return std::unique_ptr( - new framework::components::component1()); - case component_type::component2: - return std::unique_ptr( - new framework::components::component2()); - } - throw std::runtime_error { "Invalid component type" }; +component_factory(component_type ct) noexcept(false) { + switch (ct) { + case component_type::component1: + return std::unique_ptr( + new framework::components::component1()); + case component_type::component2: + return std::unique_ptr( + new framework::components::component2()); + } + throw std::runtime_error{"Invalid component type"}; } /** @@ -48,15 +46,14 @@ component_factory(component_type ct) noexcept(false) * * @return int Application exit code */ -int main(void) -{ +int main(void) { - auto component_1 = component_factory(component_type::component1); - auto component_2 = component_factory(component_type::component2); + auto component_1 = component_factory(component_type::component1); + auto component_2 = component_factory(component_type::component2); - if (component_1->do_stuff() || component_2->do_stuff()) { - std::cout << "One of the component(s) did stuff" << std::endl; - } + if (component_1->do_stuff() || component_2->do_stuff()) { + std::cout << "One of the component(s) did stuff" << std::endl; + } - return component_1->do_other_stuff(1) + component_2->do_other_stuff(3); + return component_1->do_other_stuff(1) + component_2->do_other_stuff(3); } diff --git a/chapter02/simple_example/src/main.cpp b/chapter02/simple_example/src/main.cpp index 0fec95b..0ad1424 100644 --- a/chapter02/simple_example/src/main.cpp +++ b/chapter02/simple_example/src/main.cpp @@ -1,7 +1,6 @@ #include -int main(int, char **) -{ - std::cout << "Welcome to CMake Best Practices\n"; - return 0; +int main(int, char **) { + std::cout << "Welcome to CMake Best Practices\n"; + return 0; } diff --git a/chapter03/hello_header_only/include/hello_header_only/hello_header_only.hpp b/chapter03/hello_header_only/include/hello_header_only/hello_header_only.hpp index f99b0ad..c7a4ad8 100644 --- a/chapter03/hello_header_only/include/hello_header_only/hello_header_only.hpp +++ b/chapter03/hello_header_only/include/hello_header_only/hello_header_only.hpp @@ -4,8 +4,7 @@ #include namespace hello_header_only { -void print_hello(const std::string &name) -{ - std::cout << "Hello " << name << " from a header only library\n"; -} +void print_hello(const std::string &name) { + std::cout << "Hello " << name << " from a header only library\n"; } +} // namespace hello_header_only diff --git a/chapter03/hello_object_lib/include/hello_object/hello_object.hpp b/chapter03/hello_object_lib/include/hello_object/hello_object.hpp index d5cbe6c..fe066e4 100644 --- a/chapter03/hello_object_lib/include/hello_object/hello_object.hpp +++ b/chapter03/hello_object_lib/include/hello_object/hello_object.hpp @@ -6,14 +6,11 @@ namespace hello_object { /// Example class that is explicitly exported into a dll class HelloObject { public: - HelloObject(const std::string &name) - : name_ { name } - { - } + HelloObject(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; } // namespace hello_object diff --git a/chapter03/hello_object_lib/src/hello_object.cpp b/chapter03/hello_object_lib/src/hello_object.cpp index 3ef3225..c360c66 100644 --- a/chapter03/hello_object_lib/src/hello_object.cpp +++ b/chapter03/hello_object_lib/src/hello_object.cpp @@ -3,8 +3,7 @@ #include namespace hello_object { -void HelloObject::greet() const -{ - std::cout << "Hello " << name_ << " From an object library\n"; +void HelloObject::greet() const { + std::cout << "Hello " << name_ << " From an object library\n"; } } // namespace hello_object diff --git a/chapter03/hello_shared_lib/include/hello/hello.hpp b/chapter03/hello_shared_lib/include/hello/hello.hpp index 3ce6fb3..6a00e0b 100644 --- a/chapter03/hello_shared_lib/include/hello/hello.hpp +++ b/chapter03/hello_shared_lib/include/hello/hello.hpp @@ -7,14 +7,11 @@ namespace hello { /// Example class that is explicitly exported into a dll class CH3_HELLO_SHARED_EXPORT Hello { public: - Hello(const std::string &name) - : name_ { name } - { - } + Hello(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; -} +} // namespace hello diff --git a/chapter03/hello_shared_lib/src/hello.cpp b/chapter03/hello_shared_lib/src/hello.cpp index 5df63a9..705564c 100644 --- a/chapter03/hello_shared_lib/src/hello.cpp +++ b/chapter03/hello_shared_lib/src/hello.cpp @@ -3,8 +3,5 @@ #include "internal.hpp" namespace hello { -void Hello::greet() const -{ - details::print_impl(name_); -} -} +void Hello::greet() const { details::print_impl(name_); } +} // namespace hello diff --git a/chapter03/hello_shared_lib/src/internal.cpp b/chapter03/hello_shared_lib/src/internal.cpp index 46aa6a5..03053c3 100644 --- a/chapter03/hello_shared_lib/src/internal.cpp +++ b/chapter03/hello_shared_lib/src/internal.cpp @@ -3,8 +3,7 @@ #include namespace hello::details { -void print_impl(const std::string &name) -{ - std::cout << "Hello " << name << " from a shared library\n"; -} +void print_impl(const std::string &name) { + std::cout << "Hello " << name << " from a shared library\n"; } +} // namespace hello::details diff --git a/chapter03/hello_simple_library_example/include/hello/hello.hpp b/chapter03/hello_simple_library_example/include/hello/hello.hpp index 153fa12..d9d9ce1 100644 --- a/chapter03/hello_simple_library_example/include/hello/hello.hpp +++ b/chapter03/hello_simple_library_example/include/hello/hello.hpp @@ -6,14 +6,11 @@ namespace hello { /// Example class that is explicitly exported into a dll class Hello { public: - Hello(const std::string &name) - : name_ { name } - { - } + Hello(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; -} +} // namespace hello diff --git a/chapter03/hello_simple_library_example/src/hello.cpp b/chapter03/hello_simple_library_example/src/hello.cpp index 5df63a9..705564c 100644 --- a/chapter03/hello_simple_library_example/src/hello.cpp +++ b/chapter03/hello_simple_library_example/src/hello.cpp @@ -3,8 +3,5 @@ #include "internal.hpp" namespace hello { -void Hello::greet() const -{ - details::print_impl(name_); -} -} +void Hello::greet() const { details::print_impl(name_); } +} // namespace hello diff --git a/chapter03/hello_simple_library_example/src/internal.cpp b/chapter03/hello_simple_library_example/src/internal.cpp index 46aa6a5..03053c3 100644 --- a/chapter03/hello_simple_library_example/src/internal.cpp +++ b/chapter03/hello_simple_library_example/src/internal.cpp @@ -3,8 +3,7 @@ #include namespace hello::details { -void print_impl(const std::string &name) -{ - std::cout << "Hello " << name << " from a shared library\n"; -} +void print_impl(const std::string &name) { + std::cout << "Hello " << name << " from a shared library\n"; } +} // namespace hello::details diff --git a/chapter03/hello_static_lib/include/hello/hello.hpp b/chapter03/hello_static_lib/include/hello/hello.hpp index 153fa12..d9d9ce1 100644 --- a/chapter03/hello_static_lib/include/hello/hello.hpp +++ b/chapter03/hello_static_lib/include/hello/hello.hpp @@ -6,14 +6,11 @@ namespace hello { /// Example class that is explicitly exported into a dll class Hello { public: - Hello(const std::string &name) - : name_ { name } - { - } + Hello(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; -} +} // namespace hello diff --git a/chapter03/hello_static_lib/src/hello.cpp b/chapter03/hello_static_lib/src/hello.cpp index 5df63a9..705564c 100644 --- a/chapter03/hello_static_lib/src/hello.cpp +++ b/chapter03/hello_static_lib/src/hello.cpp @@ -3,8 +3,5 @@ #include "internal.hpp" namespace hello { -void Hello::greet() const -{ - details::print_impl(name_); -} -} +void Hello::greet() const { details::print_impl(name_); } +} // namespace hello diff --git a/chapter03/hello_static_lib/src/internal.cpp b/chapter03/hello_static_lib/src/internal.cpp index 46aa6a5..03053c3 100644 --- a/chapter03/hello_static_lib/src/internal.cpp +++ b/chapter03/hello_static_lib/src/internal.cpp @@ -3,8 +3,7 @@ #include namespace hello::details { -void print_impl(const std::string &name) -{ - std::cout << "Hello " << name << " from a shared library\n"; -} +void print_impl(const std::string &name) { + std::cout << "Hello " << name << " from a shared library\n"; } +} // namespace hello::details diff --git a/chapter03/hello_world_standalone/src/main.cpp b/chapter03/hello_world_standalone/src/main.cpp index c2ab03f..ec8c77e 100644 --- a/chapter03/hello_world_standalone/src/main.cpp +++ b/chapter03/hello_world_standalone/src/main.cpp @@ -1,6 +1,3 @@ #include -int main(int, char **) -{ - std::cout << "Welcome to chapter 3\n"; -} +int main(int, char **) { std::cout << "Welcome to chapter 3\n"; } diff --git a/chapter03/src/main.cpp b/chapter03/src/main.cpp index 5643638..d57e950 100644 --- a/chapter03/src/main.cpp +++ b/chapter03/src/main.cpp @@ -2,10 +2,9 @@ #include #include -int main(int, char **) -{ - hello_header_only::print_hello("John Doe"); - hello::Hello hello("Jane Doe"); - hello.greet(); - return 0; +int main(int, char **) { + hello_header_only::print_hello("John Doe"); + hello::Hello hello("Jane Doe"); + hello.greet(); + return 0; } diff --git a/chapter04/ex01_executable/src/main.cpp b/chapter04/ex01_executable/src/main.cpp index 92146e5..50d31b0 100644 --- a/chapter04/ex01_executable/src/main.cpp +++ b/chapter04/ex01_executable/src/main.cpp @@ -8,7 +8,4 @@ #include -int main(void) -{ - std::cout << "Hello from Chapter 4 executable!" << std::endl; -} +int main(void) { std::cout << "Hello from Chapter 4 executable!" << std::endl; } diff --git a/chapter04/ex02_static/include/chapter4/ex02/lib.hpp b/chapter04/ex02_static/include/chapter4/ex02/lib.hpp index 7c7dfb4..98d4a15 100644 --- a/chapter04/ex02_static/include/chapter4/ex02/lib.hpp +++ b/chapter04/ex02_static/include/chapter4/ex02/lib.hpp @@ -8,17 +8,15 @@ #pragma once -namespace chapter4 { -namespace ex02 { +namespace chapter4::ex02 { /** * @brief The 'greeter' class interface */ class greeter { public: - /** - * Greet the caller. - */ - void greet(); + /** + * Greet the caller. + */ + void greet(); }; // class greeter -} // namespace ex02 -} // namespace chapter4 +} // namespace chapter4::ex02 diff --git a/chapter04/ex02_static/src/lib.cpp b/chapter04/ex02_static/src/lib.cpp index 6753515..e2c0621 100644 --- a/chapter04/ex02_static/src/lib.cpp +++ b/chapter04/ex02_static/src/lib.cpp @@ -9,13 +9,8 @@ #include #include -namespace chapter4 { -namespace ex02 { +namespace chapter4::ex02 { -void greeter::greet() -{ - std::cout << "Hello, world!" << std::endl; -} +void greeter::greet() { std::cout << "Hello, world!" << std::endl; } -} // namespace ex02 -} // namespace chapter4 +} // namespace chapter4::ex02 diff --git a/chapter04/ex05_config_file_package/include/chapter4/ex05/lib.hpp b/chapter04/ex05_config_file_package/include/chapter4/ex05/lib.hpp index 81e4cc0..ef49dfe 100644 --- a/chapter04/ex05_config_file_package/include/chapter4/ex05/lib.hpp +++ b/chapter04/ex05_config_file_package/include/chapter4/ex05/lib.hpp @@ -8,17 +8,15 @@ #pragma once -namespace chapter4 { -namespace ex05 { +namespace chapter4::ex05 { /** * @brief The 'greeter' class interface */ class greeter { public: - /** - * Greet the caller. - */ - void greet(); + /** + * Greet the caller. + */ + void greet(); }; // class greeter -} // namespace ex05 -} // namespace chapter4 +} // namespace chapter4::ex05 diff --git a/chapter04/ex05_config_file_package/src/lib.cpp b/chapter04/ex05_config_file_package/src/lib.cpp index 87df3ef..36f5ce9 100644 --- a/chapter04/ex05_config_file_package/src/lib.cpp +++ b/chapter04/ex05_config_file_package/src/lib.cpp @@ -9,13 +9,8 @@ #include #include -namespace chapter4 { -namespace ex05 { +namespace chapter4::ex05 { -void greeter::greet() -{ - std::cout << "Hello, world!" << std::endl; -} +void greeter::greet() { std::cout << "Hello, world!" << std::endl; } -} // namespace ex05 -} // namespace chapter4 +} // namespace chapter4::ex05 diff --git a/chapter04/ex05_consumer/src/main.cpp b/chapter04/ex05_consumer/src/main.cpp index 96aa597..5debcf8 100644 --- a/chapter04/ex05_consumer/src/main.cpp +++ b/chapter04/ex05_consumer/src/main.cpp @@ -10,8 +10,7 @@ #include -int main(void) -{ - chapter4::ex05::greeter g; - g.greet(); +int main(void) { + chapter4::ex05::greeter g; + g.greet(); } diff --git a/chapter04/ex06_pack/executable/src/main.cpp b/chapter04/ex06_pack/executable/src/main.cpp index 8c010dc..83618c9 100644 --- a/chapter04/ex06_pack/executable/src/main.cpp +++ b/chapter04/ex06_pack/executable/src/main.cpp @@ -8,8 +8,7 @@ #include -int main(void) -{ - chapter4::ex06::greeter g; - g.greet(); +int main(void) { + chapter4::ex06::greeter g; + g.greet(); } diff --git a/chapter04/ex06_pack/library/include/chapter4/ex06/lib.hpp b/chapter04/ex06_pack/library/include/chapter4/ex06/lib.hpp index 6ac3436..b0a94ad 100644 --- a/chapter04/ex06_pack/library/include/chapter4/ex06/lib.hpp +++ b/chapter04/ex06_pack/library/include/chapter4/ex06/lib.hpp @@ -15,10 +15,10 @@ namespace ex06 { */ class greeter { public: - /** - * Greet the caller. - */ - void greet(); + /** + * Greet the caller. + */ + void greet(); }; // class greeter } // namespace ex06 } // namespace chapter4 diff --git a/chapter04/ex06_pack/library/src/lib.cpp b/chapter04/ex06_pack/library/src/lib.cpp index 116779a..2ff4ebe 100644 --- a/chapter04/ex06_pack/library/src/lib.cpp +++ b/chapter04/ex06_pack/library/src/lib.cpp @@ -12,10 +12,7 @@ namespace chapter4 { namespace ex06 { -void greeter::greet() -{ - std::cout << "Hello, world!" << std::endl; -} +void greeter::greet() { std::cout << "Hello, world!" << std::endl; } } // namespace ex06 } // namespace chapter4 diff --git a/chapter04/ex07_pack_nsis_standalone/executable/src/main.cpp b/chapter04/ex07_pack_nsis_standalone/executable/src/main.cpp index e2455c1..6118b76 100644 --- a/chapter04/ex07_pack_nsis_standalone/executable/src/main.cpp +++ b/chapter04/ex07_pack_nsis_standalone/executable/src/main.cpp @@ -13,8 +13,7 @@ #include #include -int main(int, char **) -{ - chapter4::ex07::greeter g; - g.greet(); +int main(int, char **) { + chapter4::ex07::greeter g; + g.greet(); } diff --git a/chapter04/ex07_pack_nsis_standalone/library/include/chapter4/ex07/lib.hpp b/chapter04/ex07_pack_nsis_standalone/library/include/chapter4/ex07/lib.hpp index 00121f9..ef7505e 100644 --- a/chapter04/ex07_pack_nsis_standalone/library/include/chapter4/ex07/lib.hpp +++ b/chapter04/ex07_pack_nsis_standalone/library/include/chapter4/ex07/lib.hpp @@ -15,10 +15,10 @@ namespace ex07 { */ class greeter { public: - /** - * Greet the caller. - */ - void greet(); + /** + * Greet the caller. + */ + void greet(); }; // class greeter } // namespace ex07 } // namespace chapter4 diff --git a/chapter04/ex07_pack_nsis_standalone/library/src/lib.cpp b/chapter04/ex07_pack_nsis_standalone/library/src/lib.cpp index 39adbdb..8edce0d 100644 --- a/chapter04/ex07_pack_nsis_standalone/library/src/lib.cpp +++ b/chapter04/ex07_pack_nsis_standalone/library/src/lib.cpp @@ -12,10 +12,7 @@ namespace chapter4 { namespace ex07 { -void greeter::greet() -{ - std::cout << "Hello, world!" << std::endl; -} +void greeter::greet() { std::cout << "Hello, world!" << std::endl; } } // namespace ex07 } // namespace chapter4 diff --git a/chapter05/CMakeLists.txt b/chapter05/CMakeLists.txt index 1a79f2c..f2ab7c7 100644 --- a/chapter05/CMakeLists.txt +++ b/chapter05/CMakeLists.txt @@ -15,14 +15,15 @@ project( add_subdirectory(find_package_example) add_subdirectory(find_module) add_subdirectory(fetch_content_example) -# FIXME: add_subdirectory(external_project) +add_subdirectory(external_project) # Look for the conan command on the host system, if conan is not found exclude # all conan related examples from the project find_program(CONAN_EXECUTABLE conan) if(CONAN_EXECUTABLE) - # add_subdirectory(conan_example) add_subdirectory(conan_conanfile_example) + # add_subdirectory(conan_example) + # add_subdirectory(conan_conanfile_example) else() message(STATUS "Conan not found. Will not build conan examples") endif() diff --git a/chapter05/conan_example/src/main.cpp b/chapter05/conan_example/src/main.cpp index 9df8c4f..50bec24 100644 --- a/chapter05/conan_example/src/main.cpp +++ b/chapter05/conan_example/src/main.cpp @@ -1,6 +1,5 @@ #include -int main(int, char **) -{ - fmt::print("Hello, world from the conanfile example!\n"); +int main(int, char **) { + fmt::print("Hello, world from the conanfile example!\n"); } diff --git a/chapter05/external_project/CMakeLists.txt b/chapter05/external_project/CMakeLists.txt index a60d006..c4f9890 100644 --- a/chapter05/external_project/CMakeLists.txt +++ b/chapter05/external_project/CMakeLists.txt @@ -35,7 +35,7 @@ externalproject_add_step( COMMAND ${CMAKE_COMMAND} -E tar "cvzf" ${CMAKE_CURRENT_BINARY_DIR}/licenses.tar.gz /LICENSE - DEPENDENCIES build + DEPENDEES build ALWAYS YES ) diff --git a/chapter05/external_project/src/main.cpp b/chapter05/external_project/src/main.cpp index b3279b0..c067c70 100644 --- a/chapter05/external_project/src/main.cpp +++ b/chapter05/external_project/src/main.cpp @@ -1,9 +1,8 @@ #include #include -int main(int argc, char **) -{ - Require(argc > 0, "Argc is bigger than 0"); +int main(int argc, char **) { + Require(argc > 0, "Argc is bigger than 0"); - std::cout << "Welcome to the fetch_content example\n"; + std::cout << "Welcome to the fetch_content example\n"; } diff --git a/chapter05/fetch_content_example/src/main.cpp b/chapter05/fetch_content_example/src/main.cpp index d689193..db9889c 100644 --- a/chapter05/fetch_content_example/src/main.cpp +++ b/chapter05/fetch_content_example/src/main.cpp @@ -5,10 +5,11 @@ using namespace SI::literals; -int main(int argc, char **) -{ - constexpr auto speed_of_a_swallow_in_m = 11.2_m_p_s; - constexpr SI::kilometre_per_hour_t speed_in_km = speed_of_a_swallow_in_m; +int main(int argc, char **) { + constexpr auto speed_of_a_swallow_in_m = 11.2_m_p_s; + constexpr SI::kilometre_per_hour_t speed_in_km = + speed_of_a_swallow_in_m; - std::cout << "Did you know that an unladen swallow travels at approximately " << speed_of_a_swallow_in_m << " which is " << speed_in_km << "\n"; + std::cout << "Did you know that an unladen swallow travels at approximately " + << speed_of_a_swallow_in_m << " which is " << speed_in_km << "\n"; } diff --git a/chapter05/find_module/dep/include/obscure/obscure.hpp b/chapter05/find_module/dep/include/obscure/obscure.hpp index 155f81a..6500cef 100644 --- a/chapter05/find_module/dep/include/obscure/obscure.hpp +++ b/chapter05/find_module/dep/include/obscure/obscure.hpp @@ -6,14 +6,11 @@ namespace obscure { /// Example class that is explicitly exported into a dll class Obscure { public: - Obscure(const std::string &name) - : name_ { name } - { - } + Obscure(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; -} +} // namespace obscure diff --git a/chapter05/find_module/dep/src/internal.cpp b/chapter05/find_module/dep/src/internal.cpp index c153ee4..86693d1 100644 --- a/chapter05/find_module/dep/src/internal.cpp +++ b/chapter05/find_module/dep/src/internal.cpp @@ -3,8 +3,7 @@ #include namespace obscure::details { -void print_impl(const std::string &name) -{ - std::cout << "Hello " << name << " from an obscure library\n"; -} +void print_impl(const std::string &name) { + std::cout << "Hello " << name << " from an obscure library\n"; } +} // namespace obscure::details diff --git a/chapter05/find_module/dep/src/obscure.cpp b/chapter05/find_module/dep/src/obscure.cpp index 65ef7a8..3f6a5ef 100644 --- a/chapter05/find_module/dep/src/obscure.cpp +++ b/chapter05/find_module/dep/src/obscure.cpp @@ -3,8 +3,5 @@ #include "internal.hpp" namespace obscure { -void Obscure::greet() const -{ - details::print_impl(name_); -} -} +void Obscure::greet() const { details::print_impl(name_); } +} // namespace obscure diff --git a/chapter05/find_module/src/main.cpp b/chapter05/find_module/src/main.cpp index 17a63d4..0da73d0 100644 --- a/chapter05/find_module/src/main.cpp +++ b/chapter05/find_module/src/main.cpp @@ -1,7 +1,6 @@ #include -int main(int, char **) -{ - obscure::Obscure greeter { "Arcane wizard" }; - greeter.greet(); +int main(int, char **) { + obscure::Obscure greeter{"Arcane wizard"}; + greeter.greet(); } diff --git a/chapter05/find_package_example/src/main.cpp b/chapter05/find_package_example/src/main.cpp index e9e902e..b19fbe9 100644 --- a/chapter05/find_package_example/src/main.cpp +++ b/chapter05/find_package_example/src/main.cpp @@ -5,50 +5,48 @@ #include #include -std::string sha256(const std::string &str) -{ - unsigned char hash[SHA256_DIGEST_LENGTH]; - EVP_MD_CTX *mdctx; - - if (!(mdctx = EVP_MD_CTX_new())) { - // Handle error - return ""; - } - - if (1 != EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) { - // Handle error - EVP_MD_CTX_free(mdctx); - return ""; - } - - if (1 != EVP_DigestUpdate(mdctx, str.c_str(), str.size())) { - // Handle error - EVP_MD_CTX_free(mdctx); - return ""; - } - - unsigned int hash_len; - if (1 != EVP_DigestFinal_ex(mdctx, hash, &hash_len)) { - // Handle error - EVP_MD_CTX_free(mdctx); - return ""; - } +std::string sha256(const std::string &str) { + unsigned char hash[SHA256_DIGEST_LENGTH]; + EVP_MD_CTX *mdctx; + if (!(mdctx = EVP_MD_CTX_new())) { + // Handle error + return ""; + } + + if (1 != EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) { + // Handle error + EVP_MD_CTX_free(mdctx); + return ""; + } + + if (1 != EVP_DigestUpdate(mdctx, str.c_str(), str.size())) { + // Handle error EVP_MD_CTX_free(mdctx); + return ""; + } + + unsigned int hash_len; + if (1 != EVP_DigestFinal_ex(mdctx, hash, &hash_len)) { + // Handle error + EVP_MD_CTX_free(mdctx); + return ""; + } + + EVP_MD_CTX_free(mdctx); - std::stringstream ss; - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i]; - } + std::stringstream ss; + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i]; + } - return ss.str(); + return ss.str(); } -int main(int, char **) -{ +int main(int, char **) { - const std::string message { "CMake is awesome!" }; + const std::string message{"CMake is awesome!"}; - std::cout << "The sha256 hash of the message '" << message << "' is:\n"; - std::cout << "\t" << sha256(message) << "\n"; + std::cout << "The sha256 hash of the message '" << message << "' is:\n"; + std::cout << "\t" << sha256(message) << "\n"; } diff --git a/chapter05/vcpkg_example/src/main.cpp b/chapter05/vcpkg_example/src/main.cpp index 88fff32..eb45199 100644 --- a/chapter05/vcpkg_example/src/main.cpp +++ b/chapter05/vcpkg_example/src/main.cpp @@ -1,15 +1,16 @@ #include #include -int main(int, char **) -{ +int main(int, char **) { - const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; + const char json[] = + " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, " + "\"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; - rapidjson::Document document; - document.Parse(json); + rapidjson::Document document; + document.Parse(json); - if (document.HasMember("hello")) { - std::cout << "Hello = " << document["hello"].GetString() << "\n"; - } + if (document.HasMember("hello")) { + std::cout << "Hello = " << document["hello"].GetString() << "\n"; + } } diff --git a/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator.hpp b/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator.hpp index ddbe295..b8fc886 100644 --- a/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator.hpp +++ b/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator.hpp @@ -12,8 +12,7 @@ #include -namespace chapter6 { -namespace ex01 { +namespace chapter6::ex01 { /** * @brief The basic 'calculator' class * @@ -22,51 +21,51 @@ namespace ex01 { */ class calculator : private calculator_interface { public: - /** - * Calculate the sum of two numbers, @p augend lhs and @p addend - * - * @param [in] augend The number to which @p addend is added - * @param [in] addend The number which is added to @p augend - * - * @return double Sum of two numbers, @p lhs and @p rhs - */ - virtual double sum(double augend, double addend) override; + /** + * Calculate the sum of two numbers, @p augend lhs and @p addend + * + * @param [in] augend The number to which @p addend is added + * @param [in] addend The number which is added to @p augend + * + * @return double Sum of two numbers, @p lhs and @p rhs + */ + virtual double sum(double augend, double addend) override; - /** - * Calculate the difference of @p rhs from @p lhs - * - * @param [in] minuend The number to which @p subtrahend is subtracted - * @param [in] subtrahend The number which is to be subtracted from @p minuend - * - * @return double Difference of two numbers, @p minuend and @p subtrahend - */ - virtual double sub(double minuend, double subtrahend) override; + /** + * Calculate the difference of @p rhs from @p lhs + * + * @param [in] minuend The number to which @p subtrahend is subtracted + * @param [in] subtrahend The number which is to be subtracted from @p + * minuend + * + * @return double Difference of two numbers, @p minuend and @p subtrahend + */ + virtual double sub(double minuend, double subtrahend) override; - /** - * Multiply @p multiplicand with @p multiplier - * - * @param [in] multiplicand The number which is to be multiplied by @p - * multiplier - * @param [in] multiplier The number which is to multiply @p multiplicand - * - * @return double Product of two numbers, @p multiplicand and @p multiplier - */ - virtual double mul(double multiplicand, double multiplier) override; + /** + * Multiply @p multiplicand with @p multiplier + * + * @param [in] multiplicand The number which is to be multiplied by @p + * multiplier + * @param [in] multiplier The number which is to multiply @p multiplicand + * + * @return double Product of two numbers, @p multiplicand and @p multiplier + */ + virtual double mul(double multiplicand, double multiplier) override; - /** - * Divide @p dividend with @p divisor - * - * @param [in] dividend The number to be divided by @p divisor - * @param [in] divisor The number by which @p divisor is to be divided - * - * @return double Quotient of two numbers, @p dividend and @p divisor - */ - virtual double div(double dividend, double divisor) override; + /** + * Divide @p dividend with @p divisor + * + * @param [in] dividend The number to be divided by @p divisor + * @param [in] divisor The number by which @p divisor is to be divided + * + * @return double Quotient of two numbers, @p dividend and @p divisor + */ + virtual double div(double dividend, double divisor) override; - /** - * The result of the last operation - */ - double last_result {}; + /** + * The result of the last operation + */ + double last_result{}; }; // class calculator -} // namespace ex01 -} // namespace chapter6 +} // namespace chapter6::ex01 diff --git a/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator_interface.hpp b/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator_interface.hpp index 9e69b1e..a38fa69 100644 --- a/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator_interface.hpp +++ b/chapter06/ex01_doxdocgen/include/chapter6/ex01/calculator_interface.hpp @@ -10,8 +10,7 @@ #pragma once -namespace chapter6 { -namespace ex01 { +namespace chapter6::ex01 { /** * @brief The 'calculator' class interface * @@ -19,51 +18,51 @@ namespace ex01 { */ class calculator_interface { public: - /** - * Calculate the sum of two numbers, @p augend lhs and @p addend - * - * @param [in] augend The number to which @p addend is added - * @param [in] addend The number which is added to @p augend - * - * @return double Sum of two numbers, @p lhs and @p rhs - */ - virtual double sum(double augend, double addend) = 0; + /** + * Calculate the sum of two numbers, @p augend lhs and @p addend + * + * @param [in] augend The number to which @p addend is added + * @param [in] addend The number which is added to @p augend + * + * @return double Sum of two numbers, @p lhs and @p rhs + */ + virtual double sum(double augend, double addend) = 0; - /** - * Calculate the difference of @p rhs from @p lhs - * - * @param [in] minuend The number to which @p subtrahend is subtracted - * @param [in] subtrahend The number which is to be subtracted from @p minuend - * - * @return double Difference of two numbers, @p minuend and @p subtrahend - */ - virtual double sub(double minuend, double subtrahend) = 0; + /** + * Calculate the difference of @p rhs from @p lhs + * + * @param [in] minuend The number to which @p subtrahend is subtracted + * @param [in] subtrahend The number which is to be subtracted from @p + * minuend + * + * @return double Difference of two numbers, @p minuend and @p subtrahend + */ + virtual double sub(double minuend, double subtrahend) = 0; - /** - * Multiply @p multiplicand with @p multiplier - * - * @param [in] multiplicand The number which is to be multiplied by @p - * multiplier - * @param [in] multiplier The number which is to multiply @p multiplicand - * - * @return double Product of two numbers, @p multiplicand and @p multiplier - */ - virtual double mul(double multiplicand, double multiplier) = 0; + /** + * Multiply @p multiplicand with @p multiplier + * + * @param [in] multiplicand The number which is to be multiplied by @p + * multiplier + * @param [in] multiplier The number which is to multiply @p multiplicand + * + * @return double Product of two numbers, @p multiplicand and @p multiplier + */ + virtual double mul(double multiplicand, double multiplier) = 0; - /** - * Divide @p dividend with @p divisor - * - * @param [in] dividend The number to be divided by @p divisor - * @param [in] divisor The number by which @p divisor is to be divided - * - * @return double Quotient of two numbers, @p dividend and @p divisor - */ - virtual double div(double dividend, double divisor) = 0; + /** + * Divide @p dividend with @p divisor + * + * @param [in] dividend The number to be divided by @p divisor + * @param [in] divisor The number by which @p divisor is to be divided + * + * @return double Quotient of two numbers, @p dividend and @p divisor + */ + virtual double div(double dividend, double divisor) = 0; - /** - * Destructor - */ - virtual ~calculator_interface() = default; + /** + * Destructor + */ + virtual ~calculator_interface() = default; }; // class calculator_interface -} // namespace ex01 -} // namespace chapter6 +} // namespace chapter6::ex01 diff --git a/chapter06/ex01_doxdocgen/src/calculator.cpp b/chapter06/ex01_doxdocgen/src/calculator.cpp index 9a986c7..dc2c307 100644 --- a/chapter06/ex01_doxdocgen/src/calculator.cpp +++ b/chapter06/ex01_doxdocgen/src/calculator.cpp @@ -10,28 +10,22 @@ #include -namespace chapter6 { -namespace ex01 { +namespace chapter6::ex01 { -double calculator::sum(double augend, double addend) -{ - return last_result = augend + addend; +double calculator::sum(double augend, double addend) { + return last_result = augend + addend; } -double calculator::sub(double minuend, double subtrahend) -{ - return last_result = minuend - subtrahend; +double calculator::sub(double minuend, double subtrahend) { + return last_result = minuend - subtrahend; } -double calculator::mul(double multiplicand, double multiplier) -{ - return last_result = multiplicand * multiplier; +double calculator::mul(double multiplicand, double multiplier) { + return last_result = multiplicand * multiplier; } -double calculator::div(double dividend, double divisor) -{ - return last_result = dividend / divisor; +double calculator::div(double dividend, double divisor) { + return last_result = dividend / divisor; } -} // namespace ex01 -} // namespace chapter6 +} // namespace chapter6::ex01 diff --git a/chapter06/ex01_doxdocgen/src/main.cpp b/chapter06/ex01_doxdocgen/src/main.cpp index 85aff97..7801601 100644 --- a/chapter06/ex01_doxdocgen/src/main.cpp +++ b/chapter06/ex01_doxdocgen/src/main.cpp @@ -16,14 +16,13 @@ * * @return int Exit code */ -int main(void) -{ - chapter6::ex01::calculator calc; +int main(void) { + chapter6::ex01::calculator calc; - std::cout << "5 + 6: " << calc.sum(5, 6) << std::endl; - std::cout << "5 - 6: " << calc.sub(5, 6) << std::endl; - std::cout << "5 * 6: " << calc.mul(5, 6) << std::endl; - std::cout << "5 / 6: " << calc.div(5, 6) << std::endl; + std::cout << "5 + 6: " << calc.sum(5, 6) << std::endl; + std::cout << "5 - 6: " << calc.sub(5, 6) << std::endl; + std::cout << "5 * 6: " << calc.mul(5, 6) << std::endl; + std::cout << "5 / 6: " << calc.div(5, 6) << std::endl; - // TIP OF THE DAY: return value is optional in main() function + // TIP OF THE DAY: return value is optional in main() function } diff --git a/chapter06/ex02_doxplantuml/src/main.cpp b/chapter06/ex02_doxplantuml/src/main.cpp index d13f58e..e790fc2 100644 --- a/chapter06/ex02_doxplantuml/src/main.cpp +++ b/chapter06/ex02_doxplantuml/src/main.cpp @@ -23,11 +23,10 @@ * * @return int Exit code */ -int main(void) -{ - std::cout << "Greetings from the echo application!" << std::endl; - std::string input; - while (std::getline(std::cin, input)) { - std::cout << input; - } +int main(void) { + std::cout << "Greetings from the echo application!" << std::endl; + std::string input; + while (std::getline(std::cin, input)) { + std::cout << input; + } } diff --git a/chapter07/clang_tidy_example/src/main.cpp b/chapter07/clang_tidy_example/src/main.cpp index 1f98d10..b0f6b53 100644 --- a/chapter07/clang_tidy_example/src/main.cpp +++ b/chapter07/clang_tidy_example/src/main.cpp @@ -2,14 +2,13 @@ #include struct SomeStruct { - int x; - int y; + int x; + int y; }; -int main(int, char **) -{ - std::unique_ptr ptr { new SomeStruct() }; - ptr.reset(nullptr); +int main(int, char **) { + std::unique_ptr ptr{new SomeStruct()}; + ptr.reset(nullptr); - return 0; + return 0; } diff --git a/chapter07/coverage_example/src/coverage_example/coverage_example.cpp b/chapter07/coverage_example/src/coverage_example/coverage_example.cpp index 2b4f858..0463df9 100644 --- a/chapter07/coverage_example/src/coverage_example/coverage_example.cpp +++ b/chapter07/coverage_example/src/coverage_example/coverage_example.cpp @@ -2,25 +2,24 @@ #include namespace coverage_example { -std::vector check_for_divisibilty(int i) -{ +std::vector check_for_divisibilty(int i) { - std::vector result; + std::vector result; - if (i % 2 == 0) { - result.push_back(2); - } - if (i % 3 == 0) { - result.push_back(3); - } - if (i % 5 == 0) { - result.push_back(5); - } - if (i % 7 == 0) { - result.push_back(7); - } + if (i % 2 == 0) { + result.push_back(2); + } + if (i % 3 == 0) { + result.push_back(3); + } + if (i % 5 == 0) { + result.push_back(5); + } + if (i % 7 == 0) { + result.push_back(7); + } - return result; + return result; } } // namespace coverage_example diff --git a/chapter07/coverage_example/src/coverage_test.cpp b/chapter07/coverage_example/src/coverage_test.cpp index 9d4f223..20e3b1b 100644 --- a/chapter07/coverage_example/src/coverage_test.cpp +++ b/chapter07/coverage_example/src/coverage_test.cpp @@ -4,14 +4,13 @@ #include #include -int main(int, char **) -{ +int main(int, char **) { - auto result = coverage_example::check_for_divisibilty(15); - assert(std::find(result.begin(), result.end(), 2) == result.end()); - assert(std::find(result.begin(), result.end(), 3) != result.end()); - assert(std::find(result.begin(), result.end(), 5) != result.end()); - assert(std::find(result.begin(), result.end(), 7) == result.end()); + auto result = coverage_example::check_for_divisibilty(15); + assert(std::find(result.begin(), result.end(), 2) == result.end()); + assert(std::find(result.begin(), result.end(), 3) != result.end()); + assert(std::find(result.begin(), result.end(), 5) != result.end()); + assert(std::find(result.begin(), result.end(), 7) == result.end()); - return 0; + return 0; } diff --git a/chapter07/cppcheck_example/src/main.cpp b/chapter07/cppcheck_example/src/main.cpp index 2f3da52..0a45d15 100644 --- a/chapter07/cppcheck_example/src/main.cpp +++ b/chapter07/cppcheck_example/src/main.cpp @@ -1,9 +1,8 @@ #include -int main(int, char **) -{ - int *i = new int[10]; - delete[] i; - std::cout << i[0] << "\n"; - return 0; +int main(int, char **) { + int *i = new int[10]; + delete[] i; + std::cout << i[0] << "\n"; + return 0; } diff --git a/chapter07/cpplint_example/src/main.cpp b/chapter07/cpplint_example/src/main.cpp index 2f3da52..0a45d15 100644 --- a/chapter07/cpplint_example/src/main.cpp +++ b/chapter07/cpplint_example/src/main.cpp @@ -1,9 +1,8 @@ #include -int main(int, char **) -{ - int *i = new int[10]; - delete[] i; - std::cout << i[0] << "\n"; - return 0; +int main(int, char **) { + int *i = new int[10]; + delete[] i; + std::cout << i[0] << "\n"; + return 0; } diff --git a/chapter07/custom_build_type/src/coverage_example/coverage_example.cpp b/chapter07/custom_build_type/src/coverage_example/coverage_example.cpp index 2b4f858..0463df9 100644 --- a/chapter07/custom_build_type/src/coverage_example/coverage_example.cpp +++ b/chapter07/custom_build_type/src/coverage_example/coverage_example.cpp @@ -2,25 +2,24 @@ #include namespace coverage_example { -std::vector check_for_divisibilty(int i) -{ +std::vector check_for_divisibilty(int i) { - std::vector result; + std::vector result; - if (i % 2 == 0) { - result.push_back(2); - } - if (i % 3 == 0) { - result.push_back(3); - } - if (i % 5 == 0) { - result.push_back(5); - } - if (i % 7 == 0) { - result.push_back(7); - } + if (i % 2 == 0) { + result.push_back(2); + } + if (i % 3 == 0) { + result.push_back(3); + } + if (i % 5 == 0) { + result.push_back(5); + } + if (i % 7 == 0) { + result.push_back(7); + } - return result; + return result; } } // namespace coverage_example diff --git a/chapter07/custom_build_type/src/coverage_test.cpp b/chapter07/custom_build_type/src/coverage_test.cpp index 9d4f223..20e3b1b 100644 --- a/chapter07/custom_build_type/src/coverage_test.cpp +++ b/chapter07/custom_build_type/src/coverage_test.cpp @@ -4,14 +4,13 @@ #include #include -int main(int, char **) -{ +int main(int, char **) { - auto result = coverage_example::check_for_divisibilty(15); - assert(std::find(result.begin(), result.end(), 2) == result.end()); - assert(std::find(result.begin(), result.end(), 3) != result.end()); - assert(std::find(result.begin(), result.end(), 5) != result.end()); - assert(std::find(result.begin(), result.end(), 7) == result.end()); + auto result = coverage_example::check_for_divisibilty(15); + assert(std::find(result.begin(), result.end(), 2) == result.end()); + assert(std::find(result.begin(), result.end(), 3) != result.end()); + assert(std::find(result.begin(), result.end(), 5) != result.end()); + assert(std::find(result.begin(), result.end(), 7) == result.end()); - return 0; + return 0; } diff --git a/chapter07/fixture_example/src/main.cpp b/chapter07/fixture_example/src/main.cpp index b9d32c2..84388f2 100644 --- a/chapter07/fixture_example/src/main.cpp +++ b/chapter07/fixture_example/src/main.cpp @@ -1,7 +1,3 @@ #include -int main(int, char **) -{ - - return 0; -} +int main(int, char **) { return 0; } diff --git a/chapter07/fixture_example/src/server.cpp b/chapter07/fixture_example/src/server.cpp index 0ae8064..1468d37 100644 --- a/chapter07/fixture_example/src/server.cpp +++ b/chapter07/fixture_example/src/server.cpp @@ -1,12 +1,11 @@ #include -int main(int argc, char **argv) -{ - if (argc > 1) { - std::cout << "Teardown\n"; - } else { - std::cout << "setup\n"; - } +int main(int argc, char **argv) { + if (argc > 1) { + std::cout << "Teardown\n"; + } else { + std::cout << "setup\n"; + } - return 0; + return 0; } diff --git a/chapter07/iwyu_example/src/main.cpp b/chapter07/iwyu_example/src/main.cpp index d20fee9..6df66c7 100644 --- a/chapter07/iwyu_example/src/main.cpp +++ b/chapter07/iwyu_example/src/main.cpp @@ -1,9 +1,8 @@ #include #include -int main() -{ - std::cout << "Hello World!" << std::endl; +int main() { + std::cout << "Hello World!" << std::endl; - return 0; + return 0; } diff --git a/chapter07/lwyu_example/src/main.cpp b/chapter07/lwyu_example/src/main.cpp index 5a84172..bb16711 100644 --- a/chapter07/lwyu_example/src/main.cpp +++ b/chapter07/lwyu_example/src/main.cpp @@ -1,8 +1,7 @@ #include -int main() -{ - std::cout << "Hello World!" << std::endl; +int main() { + std::cout << "Hello World!" << std::endl; - return 0; + return 0; } diff --git a/chapter07/pass_fail_criteria/src/main.cpp b/chapter07/pass_fail_criteria/src/main.cpp index 710cd3f..ae65aa6 100644 --- a/chapter07/pass_fail_criteria/src/main.cpp +++ b/chapter07/pass_fail_criteria/src/main.cpp @@ -1,15 +1,14 @@ #include -int main(int argc, char **) -{ +int main(int argc, char **) { - if (argc == 1) { - std::cout << "Error: No arguments passed\n"; - } else if (argc % 2 == 0) { - std::cout << "Success: Odd number of arguments" << std::endl; - } else { - std::cout << "Warning: Even number of arguments" << std::endl; - } + if (argc == 1) { + std::cout << "Error: No arguments passed\n"; + } else if (argc % 2 == 0) { + std::cout << "Success: Odd number of arguments" << std::endl; + } else { + std::cout << "Warning: Even number of arguments" << std::endl; + } - return argc % 2; + return argc % 2; } diff --git a/chapter07/resource_group_example/src/main.cpp b/chapter07/resource_group_example/src/main.cpp index 3b0d926..3fe367d 100644 --- a/chapter07/resource_group_example/src/main.cpp +++ b/chapter07/resource_group_example/src/main.cpp @@ -2,11 +2,10 @@ #include #include -int main(int argc, char **) -{ +int main(int argc, char **) { - using namespace std::literals::chrono_literals; - std::this_thread::sleep_for(0.2s); + using namespace std::literals::chrono_literals; + std::this_thread::sleep_for(0.2s); - return 0; + return 0; } diff --git a/chapter07/simple_sanitizer_example/src/main.cpp b/chapter07/simple_sanitizer_example/src/main.cpp index 2f3da52..0a45d15 100644 --- a/chapter07/simple_sanitizer_example/src/main.cpp +++ b/chapter07/simple_sanitizer_example/src/main.cpp @@ -1,9 +1,8 @@ #include -int main(int, char **) -{ - int *i = new int[10]; - delete[] i; - std::cout << i[0] << "\n"; - return 0; +int main(int, char **) { + int *i = new int[10]; + delete[] i; + std::cout << i[0] << "\n"; + return 0; } diff --git a/chapter07/simple_test/src/main.cpp b/chapter07/simple_test/src/main.cpp index b9d32c2..84388f2 100644 --- a/chapter07/simple_test/src/main.cpp +++ b/chapter07/simple_test/src/main.cpp @@ -1,7 +1,3 @@ #include -int main(int, char **) -{ - - return 0; -} +int main(int, char **) { return 0; } diff --git a/chapter07/test_discovery_example/src/test.cpp b/chapter07/test_discovery_example/src/test.cpp index 5f944b4..83c5859 100644 --- a/chapter07/test_discovery_example/src/test.cpp +++ b/chapter07/test_discovery_example/src/test.cpp @@ -2,24 +2,11 @@ #include -std::uint64_t Fibonacci(std::uint64_t number) -{ - return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); +std::uint64_t Fibonacci(std::uint64_t number) { + return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); } -TEST_CASE("Fibonacci(0) returns 1") -{ - REQUIRE(Fibonacci(0) == 1); -} -TEST_CASE("Fibonacci(1) returns 1") -{ - REQUIRE(Fibonacci(1) == 1); -} -TEST_CASE("Fibonacci(2) returns 2") -{ - REQUIRE(Fibonacci(2) == 2); -} -TEST_CASE("Fibonacci(5) returns 8") -{ - REQUIRE(Fibonacci(5) == 8); -} +TEST_CASE("Fibonacci(0) returns 1") { REQUIRE(Fibonacci(0) == 1); } +TEST_CASE("Fibonacci(1) returns 1") { REQUIRE(Fibonacci(1) == 1); } +TEST_CASE("Fibonacci(2) returns 2") { REQUIRE(Fibonacci(2) == 2); } +TEST_CASE("Fibonacci(5) returns 8") { REQUIRE(Fibonacci(5) == 8); } diff --git a/chapter07/test_labels/src/main.cpp b/chapter07/test_labels/src/main.cpp index 114f253..133fd79 100644 --- a/chapter07/test_labels/src/main.cpp +++ b/chapter07/test_labels/src/main.cpp @@ -1,7 +1,3 @@ #include -int main(int argc, char **) -{ - - return argc % 2 == 0; -} +int main(int argc, char **) { return argc % 2 == 0; } diff --git a/chapter07/timeout_example/src/main.cpp b/chapter07/timeout_example/src/main.cpp index 31c481d..39c2bbb 100644 --- a/chapter07/timeout_example/src/main.cpp +++ b/chapter07/timeout_example/src/main.cpp @@ -2,11 +2,10 @@ #include #include -int main(int argc, char **) -{ +int main(int argc, char **) { - using namespace std::literals::chrono_literals; - std::this_thread::sleep_for(0.5s); + using namespace std::literals::chrono_literals; + std::this_thread::sleep_for(0.5s); - return 0; + return 0; } diff --git a/chapter08/chaining_custom_commands_example/src/main.cpp b/chapter08/chaining_custom_commands_example/src/main.cpp index fdedeaa..138eab7 100644 --- a/chapter08/chaining_custom_commands_example/src/main.cpp +++ b/chapter08/chaining_custom_commands_example/src/main.cpp @@ -1,7 +1,6 @@ #include -int main() -{ - std::cout << "Welcome to a the clang-format example!" << std::endl; - return 0; +int main() { + std::cout << "Welcome to a the clang-format example!" << std::endl; + return 0; } diff --git a/chapter08/configure_file_example/src/main.cpp b/chapter08/configure_file_example/src/main.cpp index 1c902bf..1baa225 100644 --- a/chapter08/configure_file_example/src/main.cpp +++ b/chapter08/configure_file_example/src/main.cpp @@ -2,8 +2,7 @@ #include "version.h" -int main() -{ - std::cout << "This file was built on the git revision: " - << CMAKE_BEST_PRACTICES_VERSION << std::endl; +int main() { + std::cout << "This file was built on the git revision: " + << CMAKE_BEST_PRACTICES_VERSION << std::endl; } diff --git a/chapter08/custom_command_example/src/main.cpp b/chapter08/custom_command_example/src/main.cpp index fdedeaa..138eab7 100644 --- a/chapter08/custom_command_example/src/main.cpp +++ b/chapter08/custom_command_example/src/main.cpp @@ -1,7 +1,6 @@ #include -int main() -{ - std::cout << "Welcome to a the clang-format example!" << std::endl; - return 0; +int main() { + std::cout << "Welcome to a the clang-format example!" << std::endl; + return 0; } diff --git a/chapter08/custom_target_dependency_example/src/main.cpp b/chapter08/custom_target_dependency_example/src/main.cpp index fdedeaa..138eab7 100644 --- a/chapter08/custom_target_dependency_example/src/main.cpp +++ b/chapter08/custom_target_dependency_example/src/main.cpp @@ -1,7 +1,6 @@ #include -int main() -{ - std::cout << "Welcome to a the clang-format example!" << std::endl; - return 0; +int main() { + std::cout << "Welcome to a the clang-format example!" << std::endl; + return 0; } diff --git a/chapter08/execute_process_example/src/main.cpp b/chapter08/execute_process_example/src/main.cpp index 757f084..8ad4ad8 100644 --- a/chapter08/execute_process_example/src/main.cpp +++ b/chapter08/execute_process_example/src/main.cpp @@ -6,8 +6,7 @@ const char git_rev[] = VERSION; -int main() -{ - std::cout << "This file was built on the git revision: " << git_rev - << std::endl; +int main() { + std::cout << "This file was built on the git revision: " << git_rev + << std::endl; } diff --git a/chapter10/ex01_external_deps/src/benchmarks.cpp b/chapter10/ex01_external_deps/src/benchmarks.cpp index 51b00b5..ddf226c 100644 --- a/chapter10/ex01_external_deps/src/benchmarks.cpp +++ b/chapter10/ex01_external_deps/src/benchmarks.cpp @@ -12,12 +12,11 @@ #include // Define a simple benchmark -static void string_append(::benchmark::State &st) -{ - std::string s; - for (auto _ : st) { - s += "a"; - } +static void string_append(::benchmark::State &st) { + std::string s; + for (auto _ : st) { + s += "a"; + } } // Register benchmark function diff --git a/chapter10/ex01_external_deps/src/tests.cpp b/chapter10/ex01_external_deps/src/tests.cpp index 133c945..1940710 100644 --- a/chapter10/ex01_external_deps/src/tests.cpp +++ b/chapter10/ex01_external_deps/src/tests.cpp @@ -10,7 +10,4 @@ #include -TEST(simple, test) -{ - SUCCEED(); -} +TEST(simple, test) { SUCCEED(); } diff --git a/chapter10/ex02_external_deps_with_extproject/src/tests.cpp b/chapter10/ex02_external_deps_with_extproject/src/tests.cpp index fe44365..7e51f6b 100644 --- a/chapter10/ex02_external_deps_with_extproject/src/tests.cpp +++ b/chapter10/ex02_external_deps_with_extproject/src/tests.cpp @@ -15,15 +15,13 @@ #include -unsigned int Factorial(unsigned int number) -{ - return number <= 1 ? number : Factorial(number - 1) * number; +unsigned int Factorial(unsigned int number) { + return number <= 1 ? number : Factorial(number - 1) * number; } -TEST_CASE("Factorials are computed", "[factorial]") -{ - REQUIRE(Factorial(1) == 1); - REQUIRE(Factorial(2) == 2); - REQUIRE(Factorial(3) == 6); - REQUIRE(Factorial(10) == 3628800); +TEST_CASE("Factorials are computed", "[factorial]") { + REQUIRE(Factorial(1) == 1); + REQUIRE(Factorial(2) == 2); + REQUIRE(Factorial(3) == 6); + REQUIRE(Factorial(10) == 3628800); } diff --git a/chapter10/ex03_simple_qt_app/main.cpp b/chapter10/ex03_simple_qt_app/main.cpp index 459b8e7..b913c6d 100644 --- a/chapter10/ex03_simple_qt_app/main.cpp +++ b/chapter10/ex03_simple_qt_app/main.cpp @@ -11,11 +11,10 @@ #include #include -int main(int argc, char **argv) -{ - QApplication a(argc, argv); - QPushButton hello("Hello from CMake Best Practices!", 0); - hello.resize(250, 30); - hello.show(); - return a.exec(); +int main(int argc, char **argv) { + QApplication a(argc, argv); + QPushButton hello("Hello from CMake Best Practices!", 0); + hello.resize(250, 30); + hello.show(); + return a.exec(); } diff --git a/chapter11/framework_example/include/hello/hello.hpp b/chapter11/framework_example/include/hello/hello.hpp index d6b31ff..d9d9ce1 100644 --- a/chapter11/framework_example/include/hello/hello.hpp +++ b/chapter11/framework_example/include/hello/hello.hpp @@ -6,14 +6,11 @@ namespace hello { /// Example class that is explicitly exported into a dll class Hello { public: - Hello(const std::string &name) - : name_ { name } - { - } + Hello(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; } // namespace hello diff --git a/chapter11/framework_example/src/hello.cpp b/chapter11/framework_example/src/hello.cpp index 5df63a9..705564c 100644 --- a/chapter11/framework_example/src/hello.cpp +++ b/chapter11/framework_example/src/hello.cpp @@ -3,8 +3,5 @@ #include "internal.hpp" namespace hello { -void Hello::greet() const -{ - details::print_impl(name_); -} -} +void Hello::greet() const { details::print_impl(name_); } +} // namespace hello diff --git a/chapter11/framework_example/src/internal.cpp b/chapter11/framework_example/src/internal.cpp index 46aa6a5..03053c3 100644 --- a/chapter11/framework_example/src/internal.cpp +++ b/chapter11/framework_example/src/internal.cpp @@ -3,8 +3,7 @@ #include namespace hello::details { -void print_impl(const std::string &name) -{ - std::cout << "Hello " << name << " from a shared library\n"; -} +void print_impl(const std::string &name) { + std::cout << "Hello " << name << " from a shared library\n"; } +} // namespace hello::details diff --git a/chapter12/android-example/include/hello/hello.hpp b/chapter12/android-example/include/hello/hello.hpp index 153fa12..d9d9ce1 100644 --- a/chapter12/android-example/include/hello/hello.hpp +++ b/chapter12/android-example/include/hello/hello.hpp @@ -6,14 +6,11 @@ namespace hello { /// Example class that is explicitly exported into a dll class Hello { public: - Hello(const std::string &name) - : name_ { name } - { - } + Hello(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; -} +} // namespace hello diff --git a/chapter12/android-example/src/hello.cpp b/chapter12/android-example/src/hello.cpp index 5df63a9..705564c 100644 --- a/chapter12/android-example/src/hello.cpp +++ b/chapter12/android-example/src/hello.cpp @@ -3,8 +3,5 @@ #include "internal.hpp" namespace hello { -void Hello::greet() const -{ - details::print_impl(name_); -} -} +void Hello::greet() const { details::print_impl(name_); } +} // namespace hello diff --git a/chapter12/android-example/src/internal.cpp b/chapter12/android-example/src/internal.cpp index 46aa6a5..03053c3 100644 --- a/chapter12/android-example/src/internal.cpp +++ b/chapter12/android-example/src/internal.cpp @@ -3,8 +3,7 @@ #include namespace hello::details { -void print_impl(const std::string &name) -{ - std::cout << "Hello " << name << " from a shared library\n"; -} +void print_impl(const std::string &name) { + std::cout << "Hello " << name << " from a shared library\n"; } +} // namespace hello::details diff --git a/chapter12/check_push_pop/include/hello.hpp b/chapter12/check_push_pop/include/hello.hpp index 9a4a207..e5efa80 100644 --- a/chapter12/check_push_pop/include/hello.hpp +++ b/chapter12/check_push_pop/include/hello.hpp @@ -2,7 +2,4 @@ #include -void hello() -{ - std::cout << "Greetings\n"; -} +void hello() { std::cout << "Greetings\n"; } diff --git a/chapter12/emulator-example/src/main.cpp b/chapter12/emulator-example/src/main.cpp index 4a9130d..38e9d30 100644 --- a/chapter12/emulator-example/src/main.cpp +++ b/chapter12/emulator-example/src/main.cpp @@ -1,7 +1,6 @@ #include -int main(int, char **) -{ - std::cout << "Welcome to CMake Best Practices (on arm)\n"; - return 0; +int main(int, char **) { + std::cout << "Welcome to CMake Best Practices (on arm)\n"; + return 0; } diff --git a/chapter12/iOS_example/include/hello/hello.hpp b/chapter12/iOS_example/include/hello/hello.hpp index 153fa12..d9d9ce1 100644 --- a/chapter12/iOS_example/include/hello/hello.hpp +++ b/chapter12/iOS_example/include/hello/hello.hpp @@ -6,14 +6,11 @@ namespace hello { /// Example class that is explicitly exported into a dll class Hello { public: - Hello(const std::string &name) - : name_ { name } - { - } + Hello(const std::string &name) : name_{name} {} - void greet() const; + void greet() const; private: - const std::string name_; + const std::string name_; }; -} +} // namespace hello diff --git a/chapter12/iOS_example/src/hello.cpp b/chapter12/iOS_example/src/hello.cpp index 5df63a9..705564c 100644 --- a/chapter12/iOS_example/src/hello.cpp +++ b/chapter12/iOS_example/src/hello.cpp @@ -3,8 +3,5 @@ #include "internal.hpp" namespace hello { -void Hello::greet() const -{ - details::print_impl(name_); -} -} +void Hello::greet() const { details::print_impl(name_); } +} // namespace hello diff --git a/chapter12/iOS_example/src/internal.cpp b/chapter12/iOS_example/src/internal.cpp index 46aa6a5..03053c3 100644 --- a/chapter12/iOS_example/src/internal.cpp +++ b/chapter12/iOS_example/src/internal.cpp @@ -3,8 +3,7 @@ #include namespace hello::details { -void print_impl(const std::string &name) -{ - std::cout << "Hello " << name << " from a shared library\n"; -} +void print_impl(const std::string &name) { + std::cout << "Hello " << name << " from a shared library\n"; } +} // namespace hello::details diff --git a/chapter13/ex02_envfile_utility/test-executable/test.cpp b/chapter13/ex02_envfile_utility/test-executable/test.cpp index 9ac64fc..d69120b 100644 --- a/chapter13/ex02_envfile_utility/test-executable/test.cpp +++ b/chapter13/ex02_envfile_utility/test-executable/test.cpp @@ -8,7 +8,7 @@ #include -int main(void) -{ - std::printf("Version `%s`, author `%s`\n", TEST_PROJECT_VERSION, TEST_PROJECT_AUTHOR); +int main(void) { + std::printf("Version `%s`, author `%s`\n", TEST_PROJECT_VERSION, + TEST_PROJECT_AUTHOR); } diff --git a/chapter13/ex03_external_cmake_module/src/main.cpp b/chapter13/ex03_external_cmake_module/src/main.cpp index 8e37f75..2bc8e18 100644 --- a/chapter13/ex03_external_cmake_module/src/main.cpp +++ b/chapter13/ex03_external_cmake_module/src/main.cpp @@ -1,6 +1,3 @@ #include -int main(void) -{ - std::printf("Hello!\n"); -} +int main(void) { std::printf("Hello!\n"); } diff --git a/chapter14/precompiled_headers/src/eratosthenes.cpp b/chapter14/precompiled_headers/src/eratosthenes.cpp index e3b679d..297cbe5 100644 --- a/chapter14/precompiled_headers/src/eratosthenes.cpp +++ b/chapter14/precompiled_headers/src/eratosthenes.cpp @@ -1,17 +1,16 @@ #include "eratosthenes.h" -std::vector eratosthenes(int n) -{ - std::vector primes; - std::vector is_prime(n + 1, true); - is_prime[0] = is_prime[1] = false; - for (int i = 2; i <= n; ++i) { - if (is_prime[i]) { - primes.push_back(i); - for (int j = i * i; j <= n; j += i) { - is_prime[j] = false; - } - } +std::vector eratosthenes(int n) { + std::vector primes; + std::vector is_prime(n + 1, true); + is_prime[0] = is_prime[1] = false; + for (int i = 2; i <= n; ++i) { + if (is_prime[i]) { + primes.push_back(i); + for (int j = i * i; j <= n; j += i) { + is_prime[j] = false; + } } - return primes; + } + return primes; } diff --git a/chapter14/precompiled_headers/src/fibonacci.cpp b/chapter14/precompiled_headers/src/fibonacci.cpp index 44ebec2..d243945 100644 --- a/chapter14/precompiled_headers/src/fibonacci.cpp +++ b/chapter14/precompiled_headers/src/fibonacci.cpp @@ -1,6 +1,5 @@ #include "fibonacci.h" -uint64_t Fibonacci(uint64_t number) -{ - return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); +uint64_t Fibonacci(uint64_t number) { + return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); } diff --git a/chapter14/precompiled_headers/src/main.cpp b/chapter14/precompiled_headers/src/main.cpp index de28755..227664c 100644 --- a/chapter14/precompiled_headers/src/main.cpp +++ b/chapter14/precompiled_headers/src/main.cpp @@ -2,14 +2,13 @@ #include "fibonacci.h" #include -int main(int, char **) -{ - std::cout << "Welcome to chapter 14\n"; - std::cout << "Fibonacci(3) = " << Fibonacci(3) << "\n"; - std::cout << "Primes before 10:\n"; - const auto primes = eratosthenes(10); - for (const auto &i : primes) { - std::cout << i << " "; - } - std::cout << "\n"; +int main(int, char **) { + std::cout << "Welcome to chapter 14\n"; + std::cout << "Fibonacci(3) = " << Fibonacci(3) << "\n"; + std::cout << "Primes before 10:\n"; + const auto primes = eratosthenes(10); + for (const auto &i : primes) { + std::cout << i << " "; + } + std::cout << "\n"; } diff --git a/chapter14/unity_build/src/eratosthenes.cpp b/chapter14/unity_build/src/eratosthenes.cpp index e3b679d..297cbe5 100644 --- a/chapter14/unity_build/src/eratosthenes.cpp +++ b/chapter14/unity_build/src/eratosthenes.cpp @@ -1,17 +1,16 @@ #include "eratosthenes.h" -std::vector eratosthenes(int n) -{ - std::vector primes; - std::vector is_prime(n + 1, true); - is_prime[0] = is_prime[1] = false; - for (int i = 2; i <= n; ++i) { - if (is_prime[i]) { - primes.push_back(i); - for (int j = i * i; j <= n; j += i) { - is_prime[j] = false; - } - } +std::vector eratosthenes(int n) { + std::vector primes; + std::vector is_prime(n + 1, true); + is_prime[0] = is_prime[1] = false; + for (int i = 2; i <= n; ++i) { + if (is_prime[i]) { + primes.push_back(i); + for (int j = i * i; j <= n; j += i) { + is_prime[j] = false; + } } - return primes; + } + return primes; } diff --git a/chapter14/unity_build/src/fibonacci.cpp b/chapter14/unity_build/src/fibonacci.cpp index 44ebec2..d243945 100644 --- a/chapter14/unity_build/src/fibonacci.cpp +++ b/chapter14/unity_build/src/fibonacci.cpp @@ -1,6 +1,5 @@ #include "fibonacci.h" -uint64_t Fibonacci(uint64_t number) -{ - return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); +uint64_t Fibonacci(uint64_t number) { + return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); } diff --git a/chapter14/unity_build/src/main.cpp b/chapter14/unity_build/src/main.cpp index de28755..227664c 100644 --- a/chapter14/unity_build/src/main.cpp +++ b/chapter14/unity_build/src/main.cpp @@ -2,14 +2,13 @@ #include "fibonacci.h" #include -int main(int, char **) -{ - std::cout << "Welcome to chapter 14\n"; - std::cout << "Fibonacci(3) = " << Fibonacci(3) << "\n"; - std::cout << "Primes before 10:\n"; - const auto primes = eratosthenes(10); - for (const auto &i : primes) { - std::cout << i << " "; - } - std::cout << "\n"; +int main(int, char **) { + std::cout << "Welcome to chapter 14\n"; + std::cout << "Fibonacci(3) = " << Fibonacci(3) << "\n"; + std::cout << "Primes before 10:\n"; + const auto primes = eratosthenes(10); + for (const auto &i : primes) { + std::cout << i << " "; + } + std::cout << "\n"; } diff --git a/chapter14/unity_build_group/src/eratosthenes.cpp b/chapter14/unity_build_group/src/eratosthenes.cpp index e3b679d..297cbe5 100644 --- a/chapter14/unity_build_group/src/eratosthenes.cpp +++ b/chapter14/unity_build_group/src/eratosthenes.cpp @@ -1,17 +1,16 @@ #include "eratosthenes.h" -std::vector eratosthenes(int n) -{ - std::vector primes; - std::vector is_prime(n + 1, true); - is_prime[0] = is_prime[1] = false; - for (int i = 2; i <= n; ++i) { - if (is_prime[i]) { - primes.push_back(i); - for (int j = i * i; j <= n; j += i) { - is_prime[j] = false; - } - } +std::vector eratosthenes(int n) { + std::vector primes; + std::vector is_prime(n + 1, true); + is_prime[0] = is_prime[1] = false; + for (int i = 2; i <= n; ++i) { + if (is_prime[i]) { + primes.push_back(i); + for (int j = i * i; j <= n; j += i) { + is_prime[j] = false; + } } - return primes; + } + return primes; } diff --git a/chapter14/unity_build_group/src/fibonacci.cpp b/chapter14/unity_build_group/src/fibonacci.cpp index 44ebec2..d243945 100644 --- a/chapter14/unity_build_group/src/fibonacci.cpp +++ b/chapter14/unity_build_group/src/fibonacci.cpp @@ -1,6 +1,5 @@ #include "fibonacci.h" -uint64_t Fibonacci(uint64_t number) -{ - return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); +uint64_t Fibonacci(uint64_t number) { + return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2); } diff --git a/chapter14/unity_build_group/src/main.cpp b/chapter14/unity_build_group/src/main.cpp index de28755..227664c 100644 --- a/chapter14/unity_build_group/src/main.cpp +++ b/chapter14/unity_build_group/src/main.cpp @@ -2,14 +2,13 @@ #include "fibonacci.h" #include -int main(int, char **) -{ - std::cout << "Welcome to chapter 14\n"; - std::cout << "Fibonacci(3) = " << Fibonacci(3) << "\n"; - std::cout << "Primes before 10:\n"; - const auto primes = eratosthenes(10); - for (const auto &i : primes) { - std::cout << i << " "; - } - std::cout << "\n"; +int main(int, char **) { + std::cout << "Welcome to chapter 14\n"; + std::cout << "Fibonacci(3) = " << Fibonacci(3) << "\n"; + std::cout << "Primes before 10:\n"; + const auto primes = eratosthenes(10); + for (const auto &i : primes) { + std::cout << i << " "; + } + std::cout << "\n"; }