liburing4cpp | Modern C++ binding for liburing that features
kandi X-RAY | liburing4cpp Summary
kandi X-RAY | liburing4cpp Summary
Modern C++ binding for liburing that uses C++20 Coroutines ( but still compiles for clang at C++17 mode with -fcoroutines-ts ). Originally named liburing-http-demo ( this project was originally started for demo ).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of liburing4cpp
liburing4cpp Key Features
liburing4cpp Examples and Code Snippets
Community Discussions
Trending Discussions on liburing4cpp
QUESTION
#include
#include
#include
#include
template
struct Promise {
std::variant<
std::monostate,
std::conditional_t, std::monostate, T>,
std::exception_ptr
> result_;
T await_resume() const {
assert(result_.index() > 0);
#if 1
// old code that I want to optimise
if (result_.index() == 2) {
std::rethrow_exception(std::get<2>(result_));
}
if constexpr (!std::is_void_v) {
return std::get<1>(result_);
}
#else
// new code, won't compile
return std::visit([](auto&& arg) {
using TT = std::decay_t;
if constexpr (!std::is_same_v) {
std::rethrow_exception(arg);
} else if constexpr (!std::is_void_v) {
return arg;
}
});
#endif
}
};
template int Promise::await_resume() const;
template std::exception_ptr Promise::await_resume() const;
template void Promise::await_resume() const;
...ANSWER
Answered 2020-Jan-22 at 06:36visit
doesn't "optimise" code - it's just a good pattern for matching on the variant
, and it's especially useful to ensure that you didn't forget any types.
But one of the requirements of visit
is that each alternative has to return the same type. This is especially problematic in your use case, since only one of your alternatives should be returned... so it's just not a good fit. You also need to handle the monostate
case in the visit
, and you really have no way to do that (besides... throwing?) so you're just out of luck.
The version you had before is perfectly fine, I would just annotate it with types a bit to be more expressive:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install liburing4cpp
Build liburing and install, the latest version required
sudo apt install clang libc++-dev libc++abi-dev. Make sure clang version >= 9
git clone --recurse-submodules https://github.com/CarterLi/liburing4cpp.git
cd liburing4cpp/demo && make
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page