From fd77582f19c3dc704f9e3ed1e04410b5ad832b4a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 10:08:53 +0000 Subject: [PATCH 1/7] Initial plan From 663e0bd7a0f83ceea41b7c0f0eb109bca48f1d7e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 10:11:03 +0000 Subject: [PATCH 2/7] Add Copilot instructions for RingBufferCpp repository Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com> --- .github/copilot-instructions.md | 106 ++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .github/copilot-instructions.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..effb355 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,106 @@ +# Copilot Instructions for RingBufferCpp + +## Project Overview + +This is a modern, header-only C++17 ring buffer (circular buffer) implementation designed for performance, safety, and ease of use. The project demonstrates C++17 best practices and is tested with Google Test. + +## Architecture + +- **Header-only library**: All implementation is in `RingBuffer.hpp` +- **Template-based**: Generic implementation using `template` +- **Namespace**: All code is in the `buffers` namespace +- **Iterator support**: Custom forward iterators in `buffers::detail` namespace + +## Code Standards + +### C++ Version and Style + +- Use **C++17** features and idioms +- Follow modern C++ best practices: + - Perfect forwarding with `std::forward` + - `constexpr if` for compile-time branching + - Conditional `noexcept` specifications + - RAII and strong exception safety guarantees + - `[[nodiscard]]` attributes where appropriate + +### Naming Conventions + +- **Classes/Types**: `snake_case` (e.g., `ring_buffer`, `ring_buffer_iterator`) +- **Member variables**: `snake_case_` with trailing underscore (e.g., `source_`, `index_`, `count_`) +- **Functions/Methods**: `snake_case` (e.g., `push_back`, `pop_front`, `cbegin`) +- **Template parameters**: PascalCase (e.g., `T`, `N`, `Overwrite`, `C`) + +### Code Organization + +- Place implementation details in `buffers::detail` namespace +- Use forward declarations before implementation +- Include necessary headers at the top (``, ``, ``, ``, ``) +- Use `#pragma once` for header guards + +## Building and Testing + +### Build Commands + +```bash +cmake -S . -B build +cmake --build build +``` + +### Test Commands + +```bash +ctest --test-dir build --output-on-failure +``` + +### Test Framework + +- Use **Google Test** framework +- Test file: `test_main.cpp` +- GoogleTest is fetched automatically via CMake's `FetchContent` +- Tests use the pattern: `TEST(RingBufferTest, TestName)` + +## Testing Guidelines + +When adding or modifying functionality: + +1. **Write tests first** or alongside implementation +2. **Test naming**: Use descriptive names like `Test1`, `Test2`, or `Test6IteratorOrder` +3. **Use Google Test macros**: `EXPECT_EQ`, `EXPECT_TRUE`, `EXPECT_FALSE`, etc. +4. **Test edge cases**: + - Empty buffer + - Full buffer + - Overwrite behavior + - Iterator operations + - Copy/move semantics +5. **Verify both const and non-const operations** where applicable + +## Key Features to Maintain + +- **Overwrite mode**: When buffer is full, new elements can overwrite oldest +- **STL-compatible interface**: `begin()`, `end()`, `cbegin()`, `cend()`, `size()`, `empty()` +- **Constant time operations**: All core operations should be O(1) +- **Exception safety**: Maintain strong exception guarantees +- **Type safety**: Use SFINAE and type traits appropriately + +## Common Patterns in This Codebase + +- Use `typename std::enable_if::type* = nullptr` for SFINAE +- Iterator comparisons based on `count()` not `index()` +- Modulo arithmetic for circular indexing: `index_ = (index_ + 1) % N` +- Template specialization for const/non-const iterators + +## What NOT to Do + +- Don't add dependencies beyond standard library (except GoogleTest for tests) +- Don't break header-only design +- Don't remove or weaken exception safety guarantees +- Don't change API to be incompatible with STL conventions +- Don't add features that would compromise O(1) operation complexity +- Avoid dynamic allocation; maintain fixed-size design + +## Special Considerations + +- The buffer size `N` is a compile-time constant (template parameter) +- Support both trivial and non-trivial types for `T` +- Handle move-only types appropriately +- Maintain compatibility with C++17 (not C++14 or earlier, unless testing Android simulation mode) From 6205737f51480623067ee3e8e863dd220cdef140 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 10:12:31 +0000 Subject: [PATCH 3/7] Address code review feedback on Copilot instructions Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com> --- .github/copilot-instructions.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index effb355..feb1aaf 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -42,14 +42,17 @@ This is a modern, header-only C++17 ring buffer (circular buffer) implementation ### Build Commands ```bash -cmake -S . -B build -cmake --build build +mkdir build && cd build +cmake .. +cmake --build . ``` ### Test Commands +From within the `build` directory: + ```bash -ctest --test-dir build --output-on-failure +ctest --output-on-failure ``` ### Test Framework @@ -103,4 +106,4 @@ When adding or modifying functionality: - The buffer size `N` is a compile-time constant (template parameter) - Support both trivial and non-trivial types for `T` - Handle move-only types appropriately -- Maintain compatibility with C++17 (not C++14 or earlier, unless testing Android simulation mode) +- Maintain compatibility with C++17 (the project has a `Simulate_Android_ToolChain` CMake option for testing C++14 compatibility without exceptions, but default is C++17) From 2039c23855c38a9fea7d9361a90893d593b8c84c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 10:13:40 +0000 Subject: [PATCH 4/7] Clarify Simulate_Android_ToolChain details in Copilot instructions Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com> --- .github/copilot-instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index feb1aaf..a0b16c0 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -106,4 +106,4 @@ When adding or modifying functionality: - The buffer size `N` is a compile-time constant (template parameter) - Support both trivial and non-trivial types for `T` - Handle move-only types appropriately -- Maintain compatibility with C++17 (the project has a `Simulate_Android_ToolChain` CMake option for testing C++14 compatibility without exceptions, but default is C++17) +- Maintain compatibility with C++17 (the project has a `Simulate_Android_ToolChain` CMake option that when enabled uses C++14 with `-fno-exceptions`, but the default is C++17) From 839ed6c3ab4c563d40bd00d7edf671583d188654 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 10:14:48 +0000 Subject: [PATCH 5/7] Improve test naming guidance and SFINAE pattern examples Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com> --- .github/copilot-instructions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index a0b16c0..5689b97 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -67,7 +67,7 @@ ctest --output-on-failure When adding or modifying functionality: 1. **Write tests first** or alongside implementation -2. **Test naming**: Use descriptive names like `Test1`, `Test2`, or `Test6IteratorOrder` +2. **Test naming**: Use descriptive names that explain what's being tested (e.g., `Test6IteratorOrder`, `BasicFunctionality`, `OverwriteBehavior`). Note: existing tests use simple numerical names like `Test1`, `Test2` for brevity. 3. **Use Google Test macros**: `EXPECT_EQ`, `EXPECT_TRUE`, `EXPECT_FALSE`, etc. 4. **Test edge cases**: - Empty buffer @@ -87,7 +87,7 @@ When adding or modifying functionality: ## Common Patterns in This Codebase -- Use `typename std::enable_if::type* = nullptr` for SFINAE +- Use SFINAE with `typename std::enable_if::type* = nullptr` pattern (e.g., `typename std::enable_if<(!Z), int>::type* = nullptr` for non-const, `typename std::enable_if<(Z), int>::type* = nullptr` for const) - Iterator comparisons based on `count()` not `index()` - Modulo arithmetic for circular indexing: `index_ = (index_ + 1) % N` - Template specialization for const/non-const iterators From 5d93a0c7622ac89c75d880839f699316392473b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 10:16:20 +0000 Subject: [PATCH 6/7] Clarify test naming convention to match project patterns Co-authored-by: bugparty <1510776+bugparty@users.noreply.github.com> --- .github/copilot-instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 5689b97..ff7153d 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -67,7 +67,7 @@ ctest --output-on-failure When adding or modifying functionality: 1. **Write tests first** or alongside implementation -2. **Test naming**: Use descriptive names that explain what's being tested (e.g., `Test6IteratorOrder`, `BasicFunctionality`, `OverwriteBehavior`). Note: existing tests use simple numerical names like `Test1`, `Test2` for brevity. +2. **Test naming**: The project uses numerical test names (`Test1`, `Test2`) with some descriptive ones (`Test6IteratorOrder`). Follow this convention for consistency. 3. **Use Google Test macros**: `EXPECT_EQ`, `EXPECT_TRUE`, `EXPECT_FALSE`, etc. 4. **Test edge cases**: - Empty buffer From 5450282694ec2a5073a83b44ee5a21bd2914952f Mon Sep 17 00:00:00 2001 From: Bowen Han Date: Sun, 18 Jan 2026 02:36:32 -0800 Subject: [PATCH 7/7] Update .github/copilot-instructions.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/copilot-instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index ff7153d..9302f18 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -89,7 +89,7 @@ When adding or modifying functionality: - Use SFINAE with `typename std::enable_if::type* = nullptr` pattern (e.g., `typename std::enable_if<(!Z), int>::type* = nullptr` for non-const, `typename std::enable_if<(Z), int>::type* = nullptr` for const) - Iterator comparisons based on `count()` not `index()` -- Modulo arithmetic for circular indexing: `index_ = (index_ + 1) % N` +- Modulo arithmetic for circular indexing: `index_ = ++index_ % N` - Template specialization for const/non-const iterators ## What NOT to Do