The following compiles for me in C++20 (MSVC). I had to add a few missing semicolons and comment out most of the calls to the
SHOW
macro, which generated errors for too many arguments. I also added spaces around template arguments to prevent left angle brackets from causing formatting problems. But the
std::optional
stuff seems to be OK.
EDIT: I uncommented the problem line (third last). I had to supply the template arguments explicitly. I'm not an expert in this, but I don't think the compiler is going to unpack the template arguments in the instantiation of
_xxx_arg
for you in order to determine what the template arguments for
optional_xxx_arg_function
are supposed to be.
#include <iostream>
#include <optional>
#define LINE_FUNC std::cout << __LINE__ << ' ' << __func__ << std::endl;
#define SHOW(_expression_) std::cout << #_expression_ << ' ' << _expression_ << std::endl;
template<typename T, typename U, U Uvalue>
struct xxx {};
template<typename T, typename U, U Uvalue>
void optional_xxx_arg_function(std::optional<xxx<T, U, Uvalue>>)
{
LINE_FUNC
}
template<typename T, typename U, U Uvalue>
void xxx_arg_function(xxx<T, U, Uvalue>)
{
LINE_FUNC
}
int main()
{
std::wcout << L"Hello World\n";
std::cout << std::boolalpha;
constexpr int value = 0x159;
using U = xxx<int, int, value>;
using T = std::optional< U >;
SHOW(typeid(U).name())
SHOW(typeid(T).name())
SHOW(typeid(std::remove_cvref_t< U >).name())
U _xxx_arg;
T _optional_xxx_arg(_xxx_arg);
xxx_arg_function(_xxx_arg);
optional_xxx_arg_function(_optional_xxx_arg);
xxx_arg_function(*_optional_xxx_arg);
optional_xxx_arg_function< int, int, value >(_xxx_arg);
return 0;
}