- operator == on vectors - 2 Updates
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jun 16 02:32AM On Tue, 2016-06-14, 嘱 Tiib wrote: > What is correct by those "conventions"? Is it 'vector::get_allocator()' or > 'vector::allocator()'? Is it 'vector::capacity()' or 'vector::get_capacity()'? > Feels there are no such "conventions". Let's say "in line with the /lack/ of naming conventions", then. > programming language therefore usage of word that is both verb and > adjective ('empty') for function name in meaning of that adjective is > misleading. Frank way of naming such function would be 'is_empty'. There doesn't seem to be a lot of is_adjective() in the standard library, though. Except in <type_traits>. ... > if (foobar.size() != 0) ... // the reality > I suspect that it is so (at least partially) because 'empty' is such a > bad name. ;-) I think that if people write such code, it's because they usually want the negation -- my "hard to spot the !" argument. I don't think I've seen size() used that way. Maybe I've been lucky. I have sometimes been tempted to write such code myself, but after an incident with std::list (where size() at least /might/ be O(n)) I hesitate to ask for more information than I'm really going to need. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jun 16 02:42AM On Tue, 2016-06-14, Wouter van Ooijen wrote: [ÖT] > contains a verb like is, has, contains, includes, etc. > The other function (the one that makes something empty) should probably > be called make_empty(). But still, the C++ containers have a different convention: bool empty() const; void clear(); For better or worse, I've adopted that convention. If I write a container-like class and need that feature, I'll use those names. I probably would even if I objected to them more than I do. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment