From 98f38b78128d72b5becb0e204d0e5e9ab1af1abb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 23 Jan 2025 09:21:02 +1000 Subject: [PATCH 1/3] Relax prohibition against "auto" Allow use of "auto" for variable types when the variable type is explicitly stated during its initialization --- qep-314-coding-style.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/qep-314-coding-style.md b/qep-314-coding-style.md index 1790bc2..16ed451 100644 --- a/qep-314-coding-style.md +++ b/qep-314-coding-style.md @@ -78,7 +78,19 @@ 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 + +``` +// 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 ); +``` + - 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. - 3.3. Checking if a pointer is null should be done with ``if ( !ptr )`` or ``if ( ptr )`` alone, omitting explicit comparison with the ``nullptr`` constant. From 5fb83e52f4ac1cf19941978a715f68c55b0e7a94 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 28 Jan 2025 08:31:36 +1000 Subject: [PATCH 2/3] 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. From fac0f3839c4232645452d7916e6dff413452ebeb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 28 Jan 2025 15:15:33 +1000 Subject: [PATCH 3/3] Update qep-314-coding-style.md Co-authored-by: Matthias Kuhn --- qep-314-coding-style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qep-314-coding-style.md b/qep-314-coding-style.md index 6263a65..6e01bba 100644 --- a/qep-314-coding-style.md +++ b/qep-314-coding-style.md @@ -77,7 +77,7 @@ 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 and lambda functions. Eg ``for ( auto it = object.begin(); ...)`` + - 3.1.1. ``auto`` should be used for complex types, such as iterators and lambda functions. Eg ``for ( auto it = object.constBegin(); ...)`` - 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 ```