I guess the author/library is unable to detect users for which this would worsen things. For me, it does actually work as an improvement on my non-smooth-scroll mousewheel.
Not sure it reimplements scrolling; it just looks like there are CSS styles applied to browsers supporting ::webkit-scrollbar-* selectors and coloring/thinning the scrollbar.
As someone that uses Microsoft's STL, I just wanted to let you know I appreciate your work. Stepping through the STL (whether on purpose or via accidental F11 instead of F10) has made me a better programmer. I mean it sincerely!
Yep, that's a totally counterproductive use of trailing return types. There are several reasons to use trailing return types, but that's not one of them. (The major use is when you have to refer to function parameters with decltype. Additional uses are when the return type would have to be qualified on the left but can be shorter on the right, or when you're returning something like a function pointer or reference to array and you don't have a convenient typedef/alias.)
One could present that argument, yes, but would be questioned as to why the argument is needed for the canonical main function definition.
Usage of this syntax for main not only deviates from expected form, its presence in defining the one function every C++ developer knows by heart is self-defeating.
In addition, it's also more consistent with lambda syntax, lets you use decltype on parameter arguments, allows your function names to line up nicely in header files, and my favorite feature, is scoped for member functions. Ex:
MessageWindow::Response MessageWindow::question(...);
MessageWindow::Icon MessageWindow::getIcon() { return _icon; }
...
auto MessageWindow::question(...) -> Response;
auto MessageWindow::getIcon() { return _icon; }
I was fairly nervous about it at first, but after using this syntax, I've grown to highly favor it. Being a huge fan of consistency, I've begun using only this style. Downside is it seems to annoy many other programmers much moreso than other style choices (like const foo vs foo const, tabs vs spaces, K&R vs 1TBS, etc.)
I do kind of wish you could say "function" instead of "auto" here, but of course that wasn't a reserved keyword so it would have broken existing code.
For the ubiquitous main, "auto main() {}" return type deduction works pretty well. But I need a wrapper around main() anyway thanks to Windows corrupting argv[] when you pass in non-ANSI (Unicode) characters. So for my case, I have:
#include <nall/main.hpp>
auto nall::main(vector<string> args) { ... }
Where internally, the real main() will use CommandLineToArgvW + WideCharToMultiByte on Windows to return UTF-8 arguments. So many cross-platform apps skip this step, and make opening files named in other languages impossible via command-line.
> In addition, it's also more consistent with lambda syntax, lets you use decltype on parameter arguments, allows your function names to line up nicely in header files...
Great points for the repurposing of auto present in the latest standard... Not for use in defining main.
Your case regarding Windows and wrapping main I'm sure is valid. But is not the case with the article's definition.
> Isn't that what the future C++ is trying to achieve? Simplified syntax?
I think your question was rhetorical, in any case the answer is yes. In fact the proposed C++ pythy syntax tries go even further http://pfultz2.github.io/Pythy/ . IIRC its Clang only. Its author hangs out on HN sometimes and would be able to provide more information
Why? Because that's the most concise way in general to iterate over an arbitrary list of enumerated values. There's no "abuse" here, just a particular example that could have been written more concisely.
It's not the most concise way to iterate over a sequence of numbers from 1 to 9. Worse than that, it suggests that there may be a number missing somewhere in the middle. You have to scan the entire sequence with your eyes to be sure.
for (int i = 1; i <= 9; ++i)
is both more concise and requires less thinking to know what's going on.
That the data he chose can be expressed as a range is utterly inconsequential. The values are never even used. In all likelihood, the author just wrote
for (auto item : {})
and then filled in the first sequence of numbers that popped into his head.
>That the data he chose can be expressed as a range is utterly inconsequential
It could be, but we don't know that. And that's exactly my point. The syntax he uses forces us to think and even speculate about that. So for the particular sequence he chose for his example, it would be less ambiguous to generate the range algorithmically.
Using a custom allocator with standard collections can be highly useful, as the article points out. I do recommend defining your own container deriving from a type such as std::vector using private inheritance, and exposing the base definitions via the "using" keyword and replicating applicable typedefs/constructors.
Doing so will help prevent "interesting" behaviour and help expose assumptive template definitions in a code base.
39 comments
[ 2.9 ms ] story [ 37.4 ms ] threadhttps://www.reddit.com/r/cpp/comments/3gd29t/c_internals_stl...
Usage of this syntax for main not only deviates from expected form, its presence in defining the one function every C++ developer knows by heart is self-defeating.
I do kind of wish you could say "function" instead of "auto" here, but of course that wasn't a reserved keyword so it would have broken existing code.
For the ubiquitous main, "auto main() {}" return type deduction works pretty well. But I need a wrapper around main() anyway thanks to Windows corrupting argv[] when you pass in non-ANSI (Unicode) characters. So for my case, I have:
Where internally, the real main() will use CommandLineToArgvW + WideCharToMultiByte on Windows to return UTF-8 arguments. So many cross-platform apps skip this step, and make opening files named in other languages impossible via command-line.Great points for the repurposing of auto present in the latest standard... Not for use in defining main.
Your case regarding Windows and wrapping main I'm sure is valid. But is not the case with the article's definition.
This comment is very interesting. His syntax reminds me of Python syntax of:
Isn't that what the future C++ is trying to achieve? Simplified syntax?I think your question was rhetorical, in any case the answer is yes. In fact the proposed C++ pythy syntax tries go even further http://pfultz2.github.io/Pythy/ . IIRC its Clang only. Its author hangs out on HN sometimes and would be able to provide more information
It could be, but we don't know that. And that's exactly my point. The syntax he uses forces us to think and even speculate about that. So for the particular sequence he chose for his example, it would be less ambiguous to generate the range algorithmically.
If you should be so inclined later.
Doing so will help prevent "interesting" behaviour and help expose assumptive template definitions in a code base.