From 840f236c6030600c5b386fe7ce01efcba0a2d851 Mon Sep 17 00:00:00 2001 From: Feiko Wielsma Date: Thu, 4 Dec 2025 16:24:56 +0000 Subject: [PATCH] Add VSCode configuration files for debugging and building with CMake; refactor main.cpp to clean up includes --- .vscode/launch.json | 16 ++++++++++++++++ .vscode/tasks.json | 37 ++++++++++++++++++++++--------------- day4/main.cpp | 10 ++-------- 3 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3b61161 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug", + "type": "lldb", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "args": [], + // CHANGE THIS LINE: + // Point the working directory to the folder containing the executable + "cwd": "${command:cmake.launchTargetDirectory}", + "preLaunchTask": "CMake: build" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 710e937..a74761c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,17 +1,24 @@ { - "version": "2.0.0", - "tasks": [ - { - "label": "CMake: Configure", - "type": "shell", - "command": "cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", - "problemMatcher": [] - }, - { - "label": "CMake: Build", - "type": "shell", - "command": "cmake --build build -- -j", - "problemMatcher": [] - } - ] + "version": "2.0.0", + "tasks": [ + { + "label": "CMake: build", + "type": "shell", + "command": "/usr/bin/cmake", + "args": [ + "--build", + "${workspaceFolder}/build", + "--config", + "Debug", + "--target", + "${command:cmake.buildTargetName}" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$gcc", + "detail": "Builds the target currently selected in the CMake status bar" + } + ] } \ No newline at end of file diff --git a/day4/main.cpp b/day4/main.cpp index dbca0f7..572cb64 100644 --- a/day4/main.cpp +++ b/day4/main.cpp @@ -1,18 +1,12 @@ -#include #include #include #include #include -#include #include -#include -#include #include -#include #include #include #include -#include #include struct Diagram { @@ -25,6 +19,7 @@ struct Diagram { auto grid() { return GridView(data.data(), height, width); } }; +namespace { auto printMap(Diagram &diagram) { auto grid = diagram.grid(); for (auto row = 0UZ; row != grid.extent(0); row++) { @@ -37,7 +32,6 @@ auto printMap(Diagram &diagram) { std::println("Width: {}", diagram.width); std::println("Height: {}", diagram.height); } - auto parseMap(const std::string &filename) -> std::expected { std::ifstream inputF{filename}; @@ -143,7 +137,7 @@ auto moveMoveablePaper(Diagram &diagram) -> long { return totalPaperRemoved; } - +} // namespace auto main() -> int { auto testCase = parseMap("test_input"); if (testCase) {