3

All overloads of assignment operators of std::slice_array are const member functions, but why is it designed so?

Maybe the reason is that std::slice_array is designed to be a proxy class, and these assignment operators just modify the referred elements without modifying the proxy class itself, so they are reasonable to be const member functions. However, why are those compound operators of std::slice_array not const member functions?

xskxzr
  • 12,442
  • 12
  • 37
  • 77

1 Answers1

4

For the first question, slice_array is just a proxy class. It has reference semantics, so none of its actual members are modified by any operation, so marking everything const gives you more usability.

For the second question, all of the operators are declared const (per the current working draft and back to C++11). For the same reason that the assignment operators are const. This is just a bug in cppreference misidentifying them. Happens.

Barry
  • 286,269
  • 29
  • 621
  • 977