H
Howard Hinnant
howardhinnant.github.io · Personal blog · on HN since 2014
Howard Hinnant, a C++ standard library designer, writes about C++ date algorithms, allocators, coding guidelines, and standard library containers.
What HN saysHN commenters cite it for the stack allocator, the container comparison page, and the date library, treating it as an authoritative C++ source.
17HN people shared it
6linked it in comments
14stories submitted
89story points
10 months agolast shared
2014people per year2026
Most-shared posts
- 1Low-Level Date Algorithms5 people · 13 points · first shared 2018 · 1 comments on HN
- 2How I Declare My Class and Why3 people · 7 points · first shared 2020 · discussion on HN
- 3Stack alloc2 people · first shared 2017
- 4C++ Coding Guidelines (2014)1 people · 52 points · first shared 2017 · 46 comments on HN
- 5Dining Philosophers Rebooted1 people · 11 points · first shared 2014 · discussion on HN
- 6This paper fully documents a date and time library for use with C++11 and C++141 people · 2 points · first shared 2015 · discussion on HN
- 7On vector bool1 people · 2 points · first shared 2017 · discussion on HN
- 8Combinations and Permutations, C++ Implementation1 people · 2 points · first shared 2019 · discussion on HN
- 9Iso week1 people · first shared 2018
- 10Unique ptr031 people · first shared 2015
- 11Smf.jpg1 people · first shared 2022
- 12Container summary1 people · first shared 2024
What HN people wrote when they linked it
jinchengJL · 2024-04-14
Having only worked with gcc and clang, OP’s code looked completely fine to me and I was baffled why many comments think the code is at fault. Judging by this page [1], I agree this is entirely MSVC’s doing.
[1] http://howardhinnant.github.io/container_summary.html
signa11 · 2023-02-05
here is an example of one from howard-hinnant: http://howardhinnant.github.io/stack_alloc.html
masklinn · 2022-10-10
If we're doing thunderdome, JS doesn't beat C++: https://howardhinnant.github.io/smf.jpg
planteen · 2018-09-24
I don't think that is what is going on, this is invoking the constructor for the weekday class with the "modern" uniform initilization syntax. This solves the old C++ most vexing parse problem.
https://en.wikipedia.org/wiki/Most_vexing_parse
It seems like this is the C++ class in question:
https://howardhinnant.github.io/date/iso_week.html
kllrnohj · 2017-04-19
C++ has way way better ways to handle this. What you do instead is a std::vector with an allocator that has a fixed-size chunk of memory to cover your common, small case and falls back to malloc if the size becomes too large to fit into the internal allocation.
Then your VLA is stack allocated when small and heap allocated when large and works everywhere, even as a return value or other cases where alloca would fail.
Example: https://howardhinnant.github.io/stack_alloc.html
danieljh · 2015-04-06
I'm bored of all the Rust vs. C++ comparisons, when the C++ code is something you simply don't write with modern and idiomatic C++11 and C++14. Not that you could not write it, but seeing this would not pass me reviewing the code.
The add_one example, as simple as it is, is a horrible example.
Why not embrace value semantics and write it like:
int add_one(int x) { return x + 1; }
There is simply no need for pointers or references. Write simple code first. To the heap allocation example:
auto x = std::make_unique<int>(5);
Even if this is a silly example, just say no to unnecessary heap allocation. Why not:
int x{5};
Now to the lifted example:
void add_one(std::unique_ptr<int> num) {
* num += 1;
}
This mixes operations with lifetime management. The add_one function does not need to care about ownership. And it does not need to take ownership of its argument. Instead on the call site do:
int add_one(int); // from above
auto p = make_unique(5);
auto six = add_one(*p); // <-
There are valid points in the blog post and I know that most snippets are meant as examples. But as someone writing C++14 you can't win me with those kinds of posts, even though I'm having a fun time playing with Rust in my spare time.
For more about modern practices see: http://klmr.me/slides/modern-cpp/
Also see Howard Hinnant's unique_ptr tutorial: http://howardhinnant.github.io/unique_ptr03.html