12

The intersection of forwarding references and overload resolution has been bugging me, and I've been caught out a few times on the wrong overload, so here's an idea.

all 5 comments
sorted by: hot top controversial new old
[-] AlmightySnoo@lemmy.world 4 points 8 months ago* (last edited 8 months ago)
[-] lawmurray@programming.dev 3 points 8 months ago

Nice. I'd not thought of that one.

[-] BaardFigur@lemmy.world 1 points 7 months ago* (last edited 7 months ago)

std::remove_const to remove the const qualifier from a type, std::remove_reference to remove the ref qualifier from a type, std::decay_t to combine the two with a little extra.

Isn't std::remove_cvref_t the combination of the first 2? What is the difference between std::remove_cvref_t and std::decay_t?

[-] lawmurray@programming.dev 1 points 7 months ago

Yes, std::remove_cvref_t combines the other two, in fact I believe it does so precisely (see the "Possible Implementation" on cppreference.com). The "...with a little extra" that I mention for std::decay_t in the article is that it does the same as std::remove_cvref_t plus some standardization of array and function types to pointer types (again, see the "Possible implementation" of it on cppreference.com). For my purposes it doesn't really matter which to use, and I mostly prefer std::decay_t for its brevity.

this post was submitted on 27 Jan 2024
12 points (100.0% liked)

C++

1754 readers
3 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS