Warning!
The version you're viewing is not the latest.
Go to the latest version
Function resource
Synopsis
#include <src/uvw/loop.h>
template <typename R, typename... Args>
std::shared_ptr< R > resource(Args &&... args)
Description
Creates resources of any type.
This should be used as a default method to create resources.
The arguments are the ones required for the specific resource.
Use it as loop->resource<uvw::TimerHandle>()
.
- Returns
- A pointer to the newly created resource.
Mentioned in
- Getting Started / Code Example
- Getting Started / Handles
- Getting Started / Requests
- Getting Started / The Loop and the Resource
- Getting Started / The event-based approach
- Getting Started / Going raw
Source
Lines 228-237 in src/uvw/loop.h.
template<typename R, typename... Args>
std::shared_ptr<R> resource(Args&&... args) {
if constexpr(std::is_base_of_v<BaseHandle, R>) {
auto ptr = R::create(shared_from_this(), std::forward<Args>(args)...);
ptr = ptr->init() ? ptr : nullptr;
return ptr;
} else {
return R::create(shared_from_this(), std::forward<Args>(args)...);
}
}