Skip to content

Instantly share code, notes, and snippets.

@detri
Created June 12, 2026 15:41
Show Gist options
  • Select an option

  • Save detri/a90f4cfa9b61c4c164588632318a3fc1 to your computer and use it in GitHub Desktop.

Select an option

Save detri/a90f4cfa9b61c4c164588632318a3fc1 to your computer and use it in GitHub Desktop.
Free function to functor adapter
// 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