From 5fb83e52f4ac1cf19941978a715f68c55b0e7a94 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 28 Jan 2025 08:31:36 +1000 Subject: [PATCH] Restrict auto for initialization to unique_ptr and shared_ptr --- qep-314-coding-style.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/qep-314-coding-style.md b/qep-314-coding-style.md index 16ed451..6263a65 100644 --- a/qep-314-coding-style.md +++ b/qep-314-coding-style.md @@ -77,18 +77,16 @@ Notes: - 3.1. For readability and ease of code review, avoid use of ``auto``. The following exceptions are permitted: - - 3.1.1. ``auto`` should be used for complex types, such as iterators. Eg ``for ( auto it = object.begin(); ...)`` - - 3.1.2. ``auto`` may be used for variable types if the type is explicit during variable initialization. Eg + - 3.1.1. ``auto`` should be used for complex types, such as iterators and lambda functions. Eg ``for ( auto it = object.begin(); ...)`` + - 3.1.2. ``auto`` may be used for ``std::unique_ptr`` and ``std::shared_ptr`` types if the pointer type is explicit during variable initialization. Eg ``` -// allowed, as the QgsPoint type is explicit during initialization: -auto pointObject = QgsPoint( 3, 4 ); // allowed, as the std::unique_ptr< QgsPoint >, std::shared_ptr< QgsPoint > types are explicit during initialization: auto pointUniquePointer = std::make_unique< QgsPoint >( 3, 4 ); auto pointSharedPointer = std::make_shared< QgsPoint >( 3, 4 ); -// NOT allowed, the argument types for the std::tuple are not explicit: -auto myTuple = std::make_tuple( 0, 5 ); +// NOT allowed, the unique_ptr type is not explicit: +auto myUniquePtr = createObjectFunction( 0, 5 ); ``` - 3.2. If ``enums`` are to be used outside of a single .h/.cpp file (or there is a reasonable chance that they will be in future!), they should be placed inside the ``Qgis`` namespace.