#define log(x) std::cout << x
using namespace std;
template<typename T>
void print(optional<T> c)
{
log(c.value_or("Input was std::nullopt"));
}
template<typename T1, typename... T2>
void print(optional<T1> c, optional<T2...> cs)
{
log(c.value_or("Input was std::nullopt")); print(cs...);
}
int main() {
optional<string> val(nullopt);
print(val);
return 1;
}
On MSVC c++20 it works just fine but with g++ -std=c++2a it gives the following error:
error: expansion pattern 'cs' contains no argument packs
void print(optional c, optional<T2...> cs) { log(c.value_or("Input was std::nullopt")); print(cs...); }
The error only happens if i pass a nullopt value in. If i would pass a normal string to the variable it would also work fine.