blob: 4a7b102c788991f390b099dce7540982338531ee [file]
// { dg-do compile { target c++26 } }
#include <functional>
#include <string>
template<typename Signature = int(int, int) const, typename F>
constexpr std::function_ref<Signature>
create(F f)
{
std::function_ref<Signature> fr(f);
return fr;
}
constexpr auto vLambda = create([](int x, int y) static { return x + y; });
constexpr auto vTgreater = create(std::greater<int>{});
constexpr auto vDgreater = create(std::greater<>{});
constexpr auto vRgreater = create(std::ranges::greater{});
constexpr auto vTplus = create(std::plus<int>{});
constexpr auto vDplus = create(std::plus<>{});
struct Empty
{
static int
operator()(int x, int y)
{ return x + y; }
};
constexpr auto vEmpty = create(Empty{});
struct NonEmpty {
int v;
static int
operator()(int x, int y)
{ return x + y; }
};
constexpr auto vNonEmpty = create(NonEmpty{3});
struct NonStatic {
int v;
int
operator()(int x, int y) const
{ return x + y + v; }
};
constexpr auto vNonType = create(std::cw<NonStatic{3}>);
struct StaticWins {
static int
operator()(int x, int y)
{ return x + y; }
int
operator()(float x, float y) const
{ return x + y; }
};
constexpr auto vStaticWins = create(StaticWins{});
struct StaticWinsET {
static int
operator()(int x, int y)
{ return x + y; }
int
operator()(this StaticWinsET, float x, float y)
{ return x + y; }
};
constexpr auto vStaticWinsET = create(StaticWinsET{});
auto func = [](std::string s) noexcept -> int
{ return s.size(); };
constexpr std::function_ref<int(std::string)> stdCompatibleFRef
= std::function_ref<int(std::string) const noexcept>(func);
constexpr std::function_ref<int(std::string&&)> implCompatible1FRef
= std::function_ref<int(std::string)>(func);
constexpr std::function_ref<int(std::string) const> implCompatible2FRef
= std::function_ref<int(std::string)>(func);