@foonathan@fosstodon.org
@foonathan@fosstodon.org avatar

foonathan

@foonathan@fosstodon.org

C++, compilers, and programming languages. Library developer @ think-cell, assistant chair for std::ranges @ C++ standardization committee.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

chandlerc, to random
@chandlerc@hachyderm.io avatar

C++ data structure API design question...

What are folks favorite ways to design a data structure that supports users providing two closely coupled custom functions? Why that pattern?

Specifically, imagine a hash table data structure that wants to allow users to deeply customize both the hash function and the equality comparison.

Current ideas, w/o ranking or even saying I like them, and interested in others:

  • A type parameter with static functions
  • two lambda template parameters
  • CRTP
foonathan,
@foonathan@fosstodon.org avatar

@chandlerc I wouldn't go with CRTP for that as it's kind of the wrong way around. I use CRTP when I want to get some boilerplate implementation for my type, not to customize something in a different type. This is especially true if the customization doesn't inject state as I assume is the case here.

So I'd go with a HashPolicy template parameter and static functions in there.

foonathan,
@foonathan@fosstodon.org avatar

@chandlerc I just find inheritance annoying to deal with. You have to manually pull in the constructor, write a protected destructor, name lookup is annoying when everything is templated and you call stuff from the base etc.

If you need state, you can also store the Policy class as a member.

foonathan,
@foonathan@fosstodon.org avatar

@chandlerc CRTP is getting a lot nicer with deducing this at least, then you don't need the Derived template parameter anymore.

There are still problems with getting typedefs from the Derived type, since it is incomplete in during the signatures and stuff...

zwarich, to random
@zwarich@hachyderm.io avatar

The worst realization that you’re aging is searching for something on Math Overflow and realizing that you answered it 8 years ago.

foonathan,
@foonathan@fosstodon.org avatar

@zwarich A couple days ago I've watched a lightning talk I gave in 2018.

Learned something new.

pervognsen, (edited ) to random
@pervognsen@mastodon.social avatar

How much RAM do you have in your dev workstation/laptop?

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen 512GB, but I also have 128 cores or so.

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen (because compiling C++ is slow...)

foonathan,
@foonathan@fosstodon.org avatar

@vitaut @pervognsen I have seen "compiler is out of heap space" error messages with MSVC.

foonathan, to cpp
@foonathan@fosstodon.org avatar

I've written a trip report for C++Now 2024, one of the best conferences I've ever attended: https://www.think-cell.com/en/career/devblog/trip-report-cpp-now-2024

vitaut, to random
@vitaut@mastodon.social avatar

Me waiting for Cassio Neri's C++ Now talk about the new FP to string conversion algorithm to be published.

foonathan,
@foonathan@fosstodon.org avatar
foonathan,
@foonathan@fosstodon.org avatar

@dougmerritt @vitaut Yes, the algorithm is a lot simpler than I thought as well!

lesley, to rust
@lesley@mastodon.gamedev.place avatar

noob question: is there a way to "catch one kind of error and propagate the other" with something cleaner than this?

foonathan,
@foonathan@fosstodon.org avatar

@lesley You generally want to stay in the monad if you want to avoid manual matching: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1b795b9c952fcec028b82e5384cc55fe

foonathan, to random
@foonathan@fosstodon.org avatar
foonathan,
@foonathan@fosstodon.org avatar

@vitaut Not yet, he'll also open source it soon.

But it's really really simple, I almost could re-derive it once after watching his talk.

foonathan, (edited ) to random
@foonathan@fosstodon.org avatar

Hypothetically, consider the following pattern matching syntax in C++:

expr match {
x => ...
}

What should this mean?
A - match expr against the existing constant x
B - match everything and introduce the name x for expr

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen Yeah, C++ isn't gonna copy that.

x => ... either always introduces a new name or always attempts name lookup for a constant. The question is what should the default be and what requires a keyword.

foonathan,
@foonathan@fosstodon.org avatar

@pervognsen That's also what I prefer, but the committee didn't like that (not my paper).

foonathan,
@foonathan@fosstodon.org avatar

@thibault There is going to be syntax to match against types, yes.

foonathan, to random
@foonathan@fosstodon.org avatar

Small tip for new speakers:

Don't end your talk with "are there any questions?" because then you get an awkward silence, then people realize it's over and start applauding, and then questions.

End it with "thank you for listening", wait for applause, then ask for questions.

vitaut, to random
@vitaut@mastodon.social avatar

new car()

foonathan,
@foonathan@fosstodon.org avatar

@vitaut new auto()

artificialmind, to random
@artificialmind@fosstodon.org avatar

Does anyone have a good resource for rationale and design decisions in IEEE 754 floating point? I'm preparing a blog post about tradeoffs in floating point design from an API perspective.

For example: why would you include +-Inf and not simply fold those into NaN? One important reason is interval arithmetic. But most "normal" float code I've seen doesn't handle Inf much better than NaN.

foonathan,
@foonathan@fosstodon.org avatar

@artificialmind @lesley I don't think the problem there is necessarily with Inf, which is just the representative for the last interval.

It's 1/(-)0 that shouldn't have been allowed IMO.

dgregor79, to random
@dgregor79@sfba.social avatar

Hello C++ folks! I've started a blog series aimed at C++ programmers who are interested in learning #SwiftLang. It teaches the breadth of the Swift language, but anchored in the features and idioms of C++. So if you know your Rule Of Fives and your SFINAEs and think you might be interested in Swift, I'd love to hear what you think. Part 1 is something you know of from C++ that Swift takes a bit further: value types. https://www.douggregor.net/posts/swift-for-cxx-practitioners-value-types/

foonathan,
@foonathan@fosstodon.org avatar

@dgregor79 How does name lookup work for extensions? Does the compiler look for extensions in all imported modules, or do you need to bring them explicitly into scope?

regehr, to random
@regehr@mastodon.social avatar

I keep running across blogs that I should follow but I don't since I don't currently have good RSS+browser integration. do people have favorite (open source or free) options here? I used to use feedly but they seem to be pushing too hard to get me to pay

foonathan,
@foonathan@fosstodon.org avatar

@lesley @regehr I also use Inoreader and pay for the cheapest plan that gives you more feeds.

foonathan, to random
@foonathan@fosstodon.org avatar

> This conversion initializes a temporary object of type T from the prvalue by evaluating the prvalue with the temporary object as its result object, and produces an xvalue denoting the temporary object.

The C++ standard is like me when I need to hit the word count requirements on an essay.

foonathan, to random
@foonathan@fosstodon.org avatar

> If you want to prompt for fingerprint and password input at the same time, you can use pam-fprint-grosshack.

Ah, Linux.

drewdevault, to random
@drewdevault@fosstodon.org avatar

Hm, bit of a long shot, but are there any physicists on here? I have a question: as the universe expands, light traveling through space is redshifted, which means it loses energy. Thermodynamics tells us that energy can't just disappear. Where does that energy go?

foonathan,
@foonathan@fosstodon.org avatar

@simrob @drewdevault @mort gestures vaguely towards quantum field theory

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • tacticalgear
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • Youngstown
  • everett
  • cisconetworking
  • slotface
  • GTA5RPClips
  • rosin
  • thenastyranch
  • kavyap
  • mdbf
  • Leos
  • modclub
  • osvaldo12
  • Durango
  • khanakhh
  • anitta
  • provamag3
  • ngwrru68w68
  • cubers
  • tester
  • ethstaker
  • megavids
  • normalnudes
  • lostlight
  • All magazines