diff --git a/docs/CPP_STYLE.md b/docs/CPP_STYLE.md index f0f4c4b6c..736093a4f 100644 --- a/docs/CPP_STYLE.md +++ b/docs/CPP_STYLE.md @@ -1,18 +1,23 @@ -# C++ Style Guide +Most of our coding style is specified in a configuration file for [ClangFormat](http://clang.llvm.org/docs/ClangFormat.html). +To automatically format a file, install `clang-format` and run: + + clang-format -i file.cpp file.hpp other_file.cpp + +--- In general, [Google's coding standard](https://google.github.io/styleguide/cppguide.html) is used, and we strongly encourage to read it. Below are our specific (but not all!) exceptions to the Google's coding standard: -- All C++ code should conform to the C++20 standard. +- All C++ code should conform to the C++23 standard. - We use `.cpp` and `.hpp` files, not `.cc` and `.h` (`.c` and `.h` are used for C code), in UTF-8 encoding. - File names are lowercase with underscores, like `file_reader.cpp`. - We use `#pragma once` instead of the `#define` Guard in header files. - Includes are sorted and grouped by directory, there should be newlines between different directories. - Order of directories in includes: "current_dir/current_file.hpp", includes from other dirs sorted by dependencies (e.g. indexer, then coding, then base), "defines.hpp", C++ standard library headers, boost headers, 3party. - We ARE using C++ exceptions. -- We are using all features of C++17 and C++20 except std::filesystem, std::to_chars & std::from_chars which are not fully supported on all platforms. -- We try to limit the usage of boost libraries which require linking (and prefer C++20 types over their boost counterparts). +- We are using all features of C++17 and C++23 except std::filesystem, std::to_chars & std::from_chars which are not fully supported on all platforms. +- We try to limit the usage of boost libraries which require linking (and prefer C++23 types over their boost counterparts). Naming and formatting @@ -21,7 +26,7 @@ Naming and formatting - Doxygen-style comments can be used. - Underscores are allowed only in prefixes for member variables and namespace names, like `int m_countriesCount; namespace utf_parser`. - Use right-to-left order for variables/params: `string const & s` (reference to the const string). -- In one line `if`, `for`, `while` we do not use brackets. If one line `for` or `while` is combined with one line `if`, do use brackets for cycle. +- In one line `if`, `for`, `while` we do not use brackets, even if a one line `for` or `while` is combined with one line `if`. - Space after the keyword in conditions and loops. Space after `;` in `for` loop. - Space between binary operators: `x = y * y + z * z`. - Space after double dash. @@ -36,13 +41,6 @@ Naming and formatting **We write code without warnings!** -## ClangFormat - -Most of our coding style is specified in a configuration file for [ClangFormat](http://clang.llvm.org/docs/ClangFormat.html). -To automatically format a file, install `clang-format` and run: - - clang-format -i file.cpp file.hpp other_file.cpp - ## Formatting Example/Guide/Reference ```cpp @@ -154,10 +152,8 @@ for (size_t i = 0; i < size; ++i) foo(i); while (true) -{ if (condition) break; -} // Space after the keyword. if (condition) @@ -195,7 +191,7 @@ v = w * (x + z); - If you see outdated code which can be improved, DO IT NOW (but in a separate pull request or commit)! - Your code should work at least on [mac|linux|android][x86|x86_64], [ios|android][x86|armv7|arm64] architectures -- Your code should compile with C++20 compiler +- Your code should compile with C++23 compiler - Avoid using any new 3party library if it is not fully tested and supported on all our platforms - Cover your code with unit tests. See examples for existing libraries - Check Base and Coding libraries for most of the basic functions