Code
#include <type_traits>
template <typename N>
concept Number = std::is_arithmetic<N>::value;
template <typename T>
concept VectorXY = requires(T t)
{
{t.x} -> Number;
{t.y} -> Number;
};
template <Number N>
struct Vec2
{
N x = 0;
N y = 0;
};
VectorXY operator*(VectorXY v, Number n)
{
return {v.x * n, v.y * n};
// error: returning initializer list
}
int main()
{
Vec2<float> v = Vec2<float>{} * 1;
// error: conversion from 'void' to non-scalar type 'Vec2<float>' requested
}
Godbolt: https://godbolt.org/z/gYsQ5B
So how do I solve this?
An explanation as to why the compiler can't infer the return type would be helpful as well.