HNHacker News
TopNewBestAskShowJobs

northwindfoo

6 karma · joined March 11, 2019

submissionscomments
northwindfoo··on Background: how we got the generics we have (2020)
Visual studio has c++ symbol rename, including class names. Has had it for a while as well. Fairly reliable, though occasionally it does fail, loudly.
northwindfoo··on Deducing This
Hmmm I'm trying to imagine the scenario. It sounds like this:

  // Structure with a function `str`, as in the paper
  struct StrHolder {

    // Assume `str` returns a `const std::string&` when `this` is const
    // and `std::string&` otherwise.
    template <class Self>
    decltype(auto) str(this Self&& self) { ... }
  };


  // Let's use it here
  void main() {
    const StrHolder s;
    s.str().size();     // OK; calling a const function on `const std::string&`
    s.str() = "abc";    // Ill-formed; compilation error here
  }
Did I get the scenario right?

If so, from what I could tell from this example, I think the error would essentially amount to "can't call operator= on const-qualified `const std::string&`". After that, it would depend on the compiler in terms of how it prints out template "frames". On Visual Studio, it would probably look pretty ugly. On Clang, might be a bit better. I don't recall how G++ prints it out. After the first line, I think it would look mostly like how any template function is expanded, which is... not that pretty.

All in all, I agree it would be a bit uglier than a plain const decorated function, but I don't think that it's bad enough to dismiss the feature, though I admit that this is subjective.

northwindfoo··on Deducing This
Agreed that modern c++ has bloat. With that said, I believe that the use case that you're describing can be solved by using concepts to constrain the "Self" template parameter, instead of allowing it to be an unconstrained generic type.
northwindfoo··on Orthodox C++
I think that about sums up my experience with boost. I've found boost to be hit and miss in terms of elegance. One of the things I've liked about the standards track is how they've cleaned up many of the same boost concepts that ultimately ended up in std.
northwindfoo··on Orthodox C++
I think it goes to show that the combination of C++ giving the developer a lot of flexibility in how to approach a problem, as well as being unopinionated, leaves room for stuff like this to be built.

There are a lot of decent ways to use templates; that link is definitely not one of them.

northwindfoo··on C++20 has been approved
I wouldn't call myself a c++ expert but I have used the language for a long time. In my opinion, templates have a lot of awesome uses outside of SFINAE and if you find yourself reaching for SFINAE, that's probably code smell and you can probably simplify the design elsewhere to avoid it.

Generally I find the best use of templates is the most basic: you want to write some code that operates on duck-types. As long as one is able to control themselves and pick the right use cases for maintainability, templates are simple enough. In my experience, this is very doable.

Concepts are also a really cool way to rein in which types are accepted as a template parameter and have a lot of potential to make templates easier to understand and teach. To me, this is the most exciting c++20 feature.

northwindfoo··on The State of Caching in Go
Right, fair enough. I only thought of that after I posted. Not used to thinking that memory is limited lol

The author did indicate that they had problems with oom and memory eviction so it probably is a memory limited use case.

northwindfoo··on The State of Caching in Go
I'm not very familiar with go but one thing I don't understand is why the caches need to be distributed. I wonder, why not just have one cache per thread?