diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-14 14:00:44 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-14 14:00:44 +0200 |
| commit | 3ab1012ea8c55f82812b5998fd6b4fdf53dea70e (patch) | |
| tree | d18552619a364fcb816d5e2d2331822edd7e2045 /cpp/examples/move_convert.cpp | |
| parent | 7b8c1e4634784b57bb6223cd780d5c67f5381d43 (diff) | |
| download | nissy-core-3ab1012ea8c55f82812b5998fd6b4fdf53dea70e.tar.gz nissy-core-3ab1012ea8c55f82812b5998fd6b4fdf53dea70e.zip | |
Improved C++ API and added info to README
Diffstat (limited to 'cpp/examples/move_convert.cpp')
| -rw-r--r-- | cpp/examples/move_convert.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cpp/examples/move_convert.cpp b/cpp/examples/move_convert.cpp new file mode 100644 index 0000000..11398df --- /dev/null +++ b/cpp/examples/move_convert.cpp | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* A simple example showing how to move a cube and print it in H48 format. */ | ||
| 2 | |||
| 3 | #include "../nissy.h" | ||
| 4 | #include <iostream> | ||
| 5 | |||
| 6 | int main() { | ||
| 7 | nissy::cube c; | ||
| 8 | if (!c.move("R' U' F").ok()) { | ||
| 9 | std::cout << "Error moving the cube!" << std::endl; | ||
| 10 | return 1; | ||
| 11 | } | ||
| 12 | |||
| 13 | auto string_or_error = c.to_string("H48"); | ||
| 14 | if (std::holds_alternative<nissy::error>(string_or_error)) { | ||
| 15 | std::cout << "Error converting cube!" << std::endl; | ||
| 16 | return 1; | ||
| 17 | } | ||
| 18 | |||
| 19 | auto str = std::get<std::string>(string_or_error); | ||
| 20 | std::cout << "Cube in H48 format after R' U' F:" << std::endl | ||
| 21 | << str << std::endl; | ||
| 22 | |||
| 23 | return 0; | ||
| 24 | } | ||
