0

I would like to overload operator << combined with the comma operator in order to provide a way of assigning multiple comma-separated values to a std::array or std::vector class member.

For example, given the following class declaration:

class MyClass{
public:
   MyClass() {}
   ~MyClass() {} 
private:
   std::array<double, 5> a_{};
}

I would like to be able to use the following syntax:

MyClass m;
m << 9, 10, 11, 99, 5;

Which in turn would update a_ by setting the corresponding values (9 at a_[0], 10 at a_[1] and so on). Operator << should also raise an error if the number of comma-separated values does not match std::array::size

Thanks for any advice on how to proceed!

BigONotation
  • 4,046
  • 5
  • 38
  • 66

0 Answers0