4 ms·
In D it is often as simple as: T front() => array[index]; void popFront() => ++index; bool empty() => index == length;
by WalterBright 4y ago
In D it is often as simple as:
T front() => array[index];
void popFront() => ++index;
bool empty() => index == length;
- tialaramex 4y agoBut your claim was that if we see this: > Something has indeed gone wrong. The struct has succumbed to being a "kitchen sink".
- WalterBright 4y agoThat was in reference to having 10s or 100s of members.
- tialaramex 4y agoBut you wrote it in reply to a description of 10s or 100s of lines of trivial members. Maybe D doesn't have such a thing, as I said I don't plan to go look, but all the other languages I used as examples certainly do. Rust's Vec has almost 50 public associated functions, a few are non-trivial, but many are, and of course they take up hundreds of lines. https://github.com/microsoft/STL/blob/main/stl/inc/vector https://github.com/microsoft/STL/blob/main/stl/inc/vector is almost 4000 lines. As I said, C++ makes even a trivial function into a horrible mess like this: _CONSTEXPR20 void shrink_to_fit() { // reduce capacity to size, provide strong guarantee auto& _My_data = _Mypair._Myval2; const pointer _Oldlast = _My_data._Mylast; if (_Oldlast != _My_data._Myend) { // something to do const pointer _Oldfirst = _My_data._Myfirst; if (_Oldfirst == _Oldlast) { _Tidy(); } else { _Reallocate_exactly(static_cast<size_type>(_Oldlast - _Oldfirst)); } } }
- hota_mazi 4y ago> void popFront() => ++index; So in D, `popFront()` not only returns... nothing (void) but then returns... an index? No wonder nobody uses this language.
- WalterBright 4y agoI made a mistake. It actually won't allow that. You'd have to write it as: void popFront() { ++index; } Thanks for pointing it out.