mit einem Klick
cpp-best-practices
// C++ development best practices. Modern C++20/23, RAII, zero-overhead abstractions, safety. Use when writing C++ code.
// C++ development best practices. Modern C++20/23, RAII, zero-overhead abstractions, safety. Use when writing C++ code.
Docker and container best practices. Multi-stage builds, security, optimization. Use when creating Dockerfiles.
Go development best practices. Idiomatic Go, error handling, concurrency patterns, testing. Use when writing Go code.
Observability best practices. Logging, metrics, tracing, alerting. Essential for production services. Use for any backend service.
React Native development. Cross-platform code, native modules, performance. Use when building mobile apps.
Test-Driven Development workflow. Write failing test first, implement code to pass, then refactor. Essential for all languages: Go, TypeScript, C++, Python. Use before any implementation task.
Use when the user wants to commit, push, and open a pull request for the current changes. Stages relevant files, writes a descriptive commit message, pushes the branch, opens a PR against main, and posts an /oc review comment so opencode automatically reviews and approves if ready.
| name | cpp-best-practices |
| description | C++ development best practices. Modern C++20/23, RAII, zero-overhead abstractions, safety. Use when writing C++ code. |
| compatibility | opencode |
Modern C++20/23 with zero-overhead abstractions and safety.
// Smart pointers — always
auto ptr = std::make_unique<Resource>();
auto shared = std::make_shared<Cache>();
// No raw new/delete
// std::vector for dynamic arrays
// std::string for strings
// Concepts (C++20)
template<typename T>
concept Hashable = requires(T a) {
{ std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
};
// Ranges (C++20)
auto results = range | std::views::filter(pred)
| std::views::transform(func)
| std::views::take(10);
// std::expected (C++23)
std::expected<int, Error> divide(int a, int b) {
if (b == 0) return std::unexpected{DivisionByZero{}};
return a / b;
}
// std::jthread for cancellation
std::jthread worker([](stop_token) {
while (!stop_token.stop_requested()) {
// work
}
});
// Exceptions for exceptional cases
// noexcept for functions that shouldn't throw
// std::expected for fallible operations
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined"
ctest --output-on-failure