switch from std expected to tl expected

This commit is contained in:
Bartosz Wieczorek 2025-11-17 18:10:50 +01:00
parent 14246d2c62
commit 4a040bb564
2 changed files with 27 additions and 2 deletions

View File

@ -36,6 +36,13 @@ FetchContent_Declare(
GIT_SHALLOW TRUE
)
FetchContent_Declare(
tl_expected
GIT_REPOSITORY https://github.com/TartanLlama/expected.git
GIT_TAG v1.1.0
)
FetchContent_MakeAvailable(tl_expected)
# c++20 format library, super usefull, super fast
set(FMT_TEST OFF CACHE INTERNAL "disabling fmt tests")
set(FMT_FUZZ OFF CACHE INTERNAL "disabling fmt fuzz")
@ -43,7 +50,7 @@ FetchContent_Declare(fmt
URL https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.zip
URL_MD5 1bba4e8bdd7b0fa98f207559ffa380a3
)
FetchContent_MakeAvailable(fmt spdlog)
FetchContent_MakeAvailable(fmt spdlog tl_expected)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# add_compile_definitions(BOOST_ASIO_ENABLE_HANDLER_TRACKING)

View File

@ -4,16 +4,34 @@
#include <boost/system/errc.hpp>
#include <boost/system/error_code.hpp>
#if __has_include(<expected>)
#include <expected>
#elif __has_include(<tl/expected.hpp>)
#include <tl/expected.hpp>
#else
#error "No expected implementation available"
#endif
namespace ranczo {
#if __has_include(<expected>)
template < typename T >
using expected = std::expected< T, boost::system::error_code >;
template < typename T >
using unexpected = std::unexpected< T >;
#elif __has_include(<tl/expected.hpp>)
template < typename T >
using expected = tl::expected< T, boost::system::error_code >;
template < typename T >
using unexpected = tl::unexpected< T >;
#else
#error "No expected implementation available"
#endif
template < typename T >
using awaitable_expected = boost::asio::awaitable< expected< T > >;