Project: soldat-cpp Type: Standard C++ with STL Build System: cmake For: Qwen AI - Simple, clear instructions
IMPORTANT: Read the AGENTS.md file in this directory first! It has all the detailed rules for this C++ project.
CRITICAL: This project was converted from a Pascal codebase.
- The original Pascal code version is tracked in
VERSION.md - IMPORTANT: If you use a newer Pascal commit to update the C++ code, you MUST update
VERSION.mdwith the new commit hash - Always check
VERSION.mdto know which Pascal code version corresponds to this C++ conversion
- The previous Pascal to C++ conversion can be found at:
~/Dev/CodexSandbox/soldat - Note: In the old conversion, some Pascal files were renamed to CapitalCase (e.g.,
unit.pasbecameUnit.pas) - When looking for corresponding files from the old conversion, remember to check for both original and CapitalCase file names
This is a standard C++ project using STL (Standard Template Library).
- STL = Standard Template Library
- It's part of standard C++
- Provides containers, algorithms, and utilities
This project uses CMake for building.
How to build:
mkdir -p build
cd build
cmake ..
make -j$(nproc)This project uses standard C++ types:
| Type | Example |
|---|---|
| String | std::string name = "hello"; |
| Vector | std::vector<int> numbers; |
| Map | std::map<std::string, int> ages; |
| Smart Pointer | std::unique_ptr<MyClass> ptr; |
// System headers first
#include <iostream>
#include <string>
#include <vector>
// Then project headers
#include "myheader.h"// WRONG - Don't use raw pointers
MyClass* ptr = new MyClass();
// ... might forget to delete!
// RIGHT - Use smart pointers
auto ptr = std::make_unique<MyClass>();
// automatically cleaned up!// OLD WAY (don't use):
for (int i = 0; i < vec.size(); i++) {
std::cout << vec[i] << std::endl;
}
// NEW WAY (do use):
for (const auto& item : vec) {
std::cout << item << std::endl;
}std::string str = "hello world";
// Find substring
auto pos = str.find("world");
if (pos != std::string::npos) {
// found!
}
// Get substring
std::string sub = str.substr(0, 5); // "hello"
// Check if ends with
bool ends = (str.rfind("world") == str.length() - 5);std::vector<int> numbers;
// Add items
numbers.push_back(1);
numbers.push_back(2);
// Iterate
for (const auto& num : numbers) {
std::cout << num << std::endl;
}
// Check size
if (!numbers.empty()) {
std::cout << "Size: " << numbers.size() << std::endl;
}std::map<std::string, int> ages;
// Add items
ages["Alice"] = 30;
ages["Bob"] = 25;
// Find item
auto it = ages.find("Alice");
if (it != ages.end()) {
std::cout << "Alice is " << it->second << std::endl;
}
// Iterate
for (const auto& [name, age] : ages) {
std::cout << name << " is " << age << std::endl;
}# Use -g for debugging symbols
# Use -O0 to disable optimization
g++ -g -O0 -Wall -Wextra myfile.cpp -o myprogram# Use -O2 or -O3 for optimization
g++ -O2 -Wall -Wextra myfile.cpp -o myprogram# If project has tests
cd build
make test
# or
ctest// WRONG
auto pos = str.find("text");
char c = str[pos]; // CRASH if not found!
// RIGHT
auto pos = str.find("text");
if (pos != std::string::npos) {
char c = str[pos]; // Safe!
}// WRONG
MyClass* obj = new MyClass();
// ... do stuff ...
// Might forget: delete obj;
// RIGHT
auto obj = std::make_unique<MyClass>();
// Automatically deleted!// WRONG - copies the string!
void printString(std::string str) {
std::cout << str << std::endl;
}
// RIGHT - no copy!
void printString(const std::string& str) {
std::cout << str << std::endl;
}#include <iostream> // std::cout, std::cin
#include <string> // std::string
#include <vector> // std::vector
#include <map> // std::map
#include <memory> // std::unique_ptr, std::shared_ptr
#include <algorithm> // std::sort, std::find- Use
autofor type deduction - Use
nullptrinstead ofNULL - Use range-based for loops
- Use smart pointers
- Use
constexprfor compile-time constants
Before you write code:
- Did I read AGENTS.md?
- Am I using std:: types (std::string, std::vector)?
- Am I using smart pointers instead of raw new/delete?
- Am I using modern C++ features (auto, range-for)?
- Did I check if find() returned a valid result?
If NO to any: STOP and fix it!
- Read AGENTS.md in this directory
- Read project README.md for specific instructions
- Check C++ Reference: https://en.cppreference.com/
- Look at existing code in the project for examples
Three most important things:
- Use STL types (std::string, std::vector, std::map)
- Use smart pointers (std::unique_ptr, std::shared_ptr)
- Use modern C++ (auto, range-for, nullptr)
Read AGENTS.md for complete details!