| name | cpp-style |
| description | C++ coding style guide based on LLVM style. Reference when working with C++ files (*.hpp, *.cpp, *.h). |
C++ Style Guide
C++ coding style guide based on LLVM style. See reference.md and examples.md for details.
Core Rules
- Style Standard: LLVM style + project modifications
- Automation Tools: clang-format, clang-tidy, cpplint (check pre-commit config)
- Line Length: Maximum 120 characters
- Indentation: 2 spaces (no tabs)
Naming Conventions
| Element | Style | Examples |
|---|
| Functions | camelBack | calculateTotal(), processData() |
| Classes | CamelCase | UserManager, PaymentProcessor |
| Variables/Parameters | camelBack | totalCount, userName |
| Constants | UPPER_SNAKE_CASE | MAX_RETRIES, DEFAULT_TIMEOUT |
| Private Members | m_ prefix | m_internalMember |
| Macros | UPPER_SNAKE_CASE | MAX_SIZE, ENABLE_FEATURE |
Header Guards
#ifndef PATH_TO_FILE_H_
#define PATH_TO_FILE_H_
#endif
#ifndef PATH_TO_FILE_HPP_
#define PATH_TO_FILE_HPP_
#endif
Include Order
- Related header
- System headers
- Standard library
- Third-party
- Local headers
#include "my_class.h"
#include <sys/types.h>
#include <string>
#include <vector>
#include <pybind11/pybind11.h>
#include "local/utils.h"
Modern C++ Practices
- Use
nullptr (not NULL or 0)
- Use
auto judiciously
- Actively use
const and constexpr
- Use range-based for loops
- Prefer smart pointers (
std::unique_ptr, std::shared_ptr)
- Use exception handling and
std::optional