Today, when working with my stripped C++ Win32 library – after the frustration with Rust’s long compile times in WinSafe –, I was trying to implement an overloaded variadic method, in order to get rid of initializer_list. Then I stumbled upon a great article which introduced me to the abbreviated function template feature of C++20, which I’m using.
This is an example:
int foo(std::wstring n)
{
OutputDebugStringW(n.data());
OutputDebugStringW(L"\n");
return 43;
}
int foo(std::wstring n, std::convertible_to<std::wstring> auto... nn)
{
foo(n);
return foo(nn...);
}
The convertible_to concept is particularly interesting in narrowing the template type.
No comments:
Post a Comment