Created
June 12, 2026 15:41
-
-
Save detri/a90f4cfa9b61c4c164588632318a3fc1 to your computer and use it in GitHub Desktop.
Free function to functor adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: 0BSD | |
| #pragma once | |
| #include <type_traits> | |
| #include <utility> | |
| namespace detri | |
| { | |
| template<class T> | |
| concept is_free_fn_ptr = std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t<T>>; | |
| template<auto Fn> | |
| requires is_free_fn_ptr<decltype(Fn)> && (Fn != nullptr) | |
| struct free_function | |
| { | |
| template<class... Args> | |
| requires requires(Args&&... args) | |
| { | |
| Fn(std::forward<Args>(args)...); | |
| } | |
| constexpr decltype(auto) operator()(Args&&... args) const | |
| noexcept(std::is_nothrow_invocable_v<decltype(Fn), Args...>) | |
| { | |
| return Fn(std::forward<Args>(args)...); | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment