'vertex'という名前のクラスの2つのバージョンがあり、1つは座標に直接アクセサーを使用します。
struct vertex
{
// Coordinates
std::array<double, 3> coords;
// Direct accessors
double & x;
double & y;
double & z;
// Constructor
template<typename... T> vertex(T &&... coordinates) :
coords{{ std::forward<T>(coordinates)... }},
x( coords[0] ), y( coords[1] ), z( coords[2] )
{ }
};
およびアクセス機能を使用するその他:
struct vertex
{
// Coordinates
std::array<double, 3> coords;
// Access functions
double & x() { return coords[0]; }
double & y() { return coords[1]; }
double & z() { return coords[2]; }
// Constructor
template<typename... T> vertex(T &&... coordinates) :
coords{{ std::forward<T>(coordinates)... }}
{ }
};
この特定のケースにはどちらのアプローチが適していますか?他の提案をいただければ幸いです。ありがとう!