Subsequent to the birth of Boost Assign, the language improved:
for (int i : {1,2,3,4,5})
v.push_back(i);
Simple, built in, anyone can understand it.11–20 of 49 posts
Subsequent to the birth of Boost Assign, the language improved:
for (int i : {1,2,3,4,5})
v.push_back(i);
Simple, built in, anyone can understand it.Earlier quoted context omitted.
That sure is a weird usage
But it has a Boost package, which means someone thought it was reasonable! I'm intentionally using a weak argument here...
We like to complain about Java but the C++ guys went all in and apparently can't seem to write a simple array without inheriting from at least 3 primitives and using a couple of templates.
Yes please tell me how you follow the "SOLID" principles when this is as frail as a house of cards
Clearly, it's over 9000!
... more seriously though, overloading the comma operator is a bad idea and you shouldn't do it. In fact, almost nobody does it.
Specifically, you don't want to break the principle of least astonishment with a command such as
v+= 1,2,3,4,5;
Assuming you want to add up a bunch of literals, what you could do is something like: std::array data { 1,2,3,4,5 };
v += std::reduce(data.begin(), data.end());
and if you've implemented some and wrappers for containers, you would have something like an template
typename Container::value_type
reduce(const Container& container);
and then you would write v += reduce(std::array{ 1,2,3,4,5 } );
which is terse and much clearer.> Overloading the Comma Operator Is Powerful Clearly, it's over 9000! ... more seriously though, overloading the comma operator is a bad idea and you shouldn't do it. In fact, almost nobody does it. Specifically, you don't want to break the principle of least astonishment with a command such as v+= 1,2,3,4,5; Assuming you want to add up a bunch of literals, what you could do is something like: std::array data { 1,2,3…
v.insert(v.end(), { 1, 2, 3, 4, 5 });> Overloading the Comma Operator Is Powerful Clearly, it's over 9000! ... more seriously though, overloading the comma operator is a bad idea and you shouldn't do it. In fact, almost nobody does it. Specifically, you don't want to break the principle of least astonishment with a command such as v+= 1,2,3,4,5; Assuming you want to add up a bunch of literals, what you could do is something like: std::array data { 1,2,3…
Earlier quoted context omitted.
But it has a Boost package, which means someone thought it was reasonable! I'm intentionally using a weak argument here...
Reasonable and "C++ library" in the same line is almost an oxymoron. We like to complain about Java but the C++ guys went all in and apparently can't seem to write a simple array without inheriting from at least 3 primitives and using a couple of templates. Yes please tell me how you follow the "SOLID" principles when this is as frail as a house of cards
The example (v += 1,2,3,4,5) is neither "nice" nor "expressive". It's confusing and dumb. The reader of this code can't be expected to know what it does. And, looking at the implementation, there's not even an efficiency benefit from doing this. You'd have a more efficient and literate program with std::iota. The rest of the article isn't wrong, but it fails to establish why anyone thinks this pattern is "nice".
a, b = 10, 20;
(This assigns 10 to b but leaves a untouched)> Overloading the Comma Operator Is Powerful Clearly, it's over 9000! ... more seriously though, overloading the comma operator is a bad idea and you shouldn't do it. In fact, almost nobody does it. Specifically, you don't want to break the principle of least astonishment with a command such as v+= 1,2,3,4,5; Assuming you want to add up a bunch of literals, what you could do is something like: std::array data { 1,2,3…
An even more concise form is built in, and I think more obvious to readers: v.insert(v.end(), { 1, 2, 3, 4, 5 });
Earlier quoted context omitted.
Reasonable and "C++ library" in the same line is almost an oxymoron. We like to complain about Java but the C++ guys went all in and apparently can't seem to write a simple array without inheriting from at least 3 primitives and using a couple of templates. Yes please tell me how you follow the "SOLID" principles when this is as frail as a house of cards
Qt is very reasonable and the standard library also isn't too bad. Boost (some of its sub-projects) is by far the worst in making simple things complicated.
The example (v += 1,2,3,4,5) is neither "nice" nor "expressive". It's confusing and dumb. The reader of this code can't be expected to know what it does. And, looking at the implementation, there's not even an efficiency benefit from doing this. You'd have a more efficient and literate program with std::iota. The rest of the article isn't wrong, but it fails to establish why anyone thinks this pattern is "nice".
As another example of unexpected behavior: a, b = 10, 20; (This assigns 10 to b but leaves a untouched)