EDIT: I was able fully minimize this question, thanks for feedbacks.
Now, i am working on a vector class(vector it is term from mathematics). This class has template for dimension and elements type. I am needing to define reference fields: X,Y, the syntax must do not require call brackets(v.X() - incorrect solution
). My implementation for this:
#include <array>
template <typename Ty, size_t Size>
struct vector {
std::array<Ty, Size> data;
Ty& x{ this->data[0] };
Ty& y{ this->data[1] };
};
constexpr vector<int, 2> const_context() {
vector<int, 2> v1{ 1,2 };
v1.data[0] = 1;
return v1;
}
int main() {
constexpr auto res = const_context();
}
If we comment x and y fields compile it is successful.
My instruments: Visual studio 2017 and C++ 17. The solution must be portable and do not depend on compiler.