rsl 1.1.0
ROS Support Library
Loading...
Searching...
No Matches
no_discard.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
5namespace rsl {
6
14template <typename Fn>
15class NoDiscard {
16 static_assert(std::is_invocable_v<Fn()>, "Fn must be invocable");
17 Fn fn_;
18
19 public:
20 NoDiscard(Fn const& fn) : fn_(fn) {}
21 template <typename... Ts>
22 [[nodiscard]] constexpr auto operator()(Ts&&... args) const
23 noexcept(noexcept(fn_(std::forward<Ts>(args)...))) {
24 return fn_(std::forward<Ts>(args)...);
25 }
26};
27
28} // namespace rsl
Template for creating lambdas with the nodiscard attribute.
Definition no_discard.hpp:15