Skip to content

Commit 729db5c

Browse files
committed
add examples
1 parent aea57aa commit 729db5c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

examples/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.23)
2+
3+
project(ystdlib-examples)
4+
5+
include("${CMAKE_SOURCE_DIR}/../build/deps/cmake-settings/settings.cmake" REQUIRED)
6+
7+
if(NOT DEFINED ystdlib_ROOT)
8+
set(ystdlib_ROOT "${CMAKE_SOURCE_DIR}/../build/build_install")
9+
endif()
10+
find_package(ystdlib REQUIRED)
11+
12+
13+
add_executable(main main.cpp)
14+
15+
target_compile_features(main PRIVATE cxx_std_20)
16+
17+
target_link_libraries(
18+
main
19+
PRIVATE
20+
ystdlib::error_handling
21+
)

examples/main.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <string>
2+
#include <ystdlib/error_handling/ErrorCode.hpp>
3+
#include <cstdint>
4+
#include <iostream>
5+
6+
#include <ystdlib/error_handling/ErrorCode.hpp>
7+
8+
enum class BinaryErrorCodeEnum : uint8_t {
9+
Success = 0,
10+
Failure
11+
};
12+
13+
using BinaryErrorCode = ystdlib::error_handling::ErrorCode<BinaryErrorCodeEnum>;
14+
15+
using BinaryErrorCategory = ystdlib::error_handling::ErrorCategory<BinaryErrorCodeEnum>;
16+
17+
constexpr std::string_view cBinaryTestErrorCategoryName{"Binary Error Code"};
18+
19+
template <>
20+
auto BinaryErrorCategory::name() const noexcept -> char const* {
21+
return cBinaryTestErrorCategoryName.data();
22+
}
23+
24+
25+
YSTDLIB_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(BinaryErrorCodeEnum);
26+
27+
int main() {
28+
// Test error codes within the same error category
29+
BinaryErrorCode const success{BinaryErrorCodeEnum::Success};
30+
31+
BinaryErrorCode const failure{BinaryErrorCodeEnum::Failure};
32+
33+
std::cout << "test is good!" << std::endl;
34+
return 0;
35+
}

0 commit comments

Comments
 (0)