News for hackers. Stuff that matters.

northwindfoo

Re:Background: how we got the generics we have (2020) on Thursday April 01, 2021 @09:09AM (#26660006)
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.
Re:Deducing This on Thursday March 18, 2021 @12:43PM (#26504584)
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.

Re:Deducing This on Thursday March 18, 2021 @07:32AM (#26501590)
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.
Re:Orthodox C++ on Sunday December 27, 2020 @09:43PM (#25556230)
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.
Re:Orthodox C++ on Sunday December 27, 2020 @06:13PM (#25555071)
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.

Re:C++20 has been approved on Sunday September 06, 2020 @10:40AM (#24391642)
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.

Re:The State of Caching in Go on Monday March 11, 2019 @12:23AM (#19356653)
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.

Re:The State of Caching in Go on Sunday March 10, 2019 @11:49PM (#19356513)
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?