C++ Weekly - Ep 254 - C++23's signed / unsigned size_t Literals

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

I'am still waiting for static type reflection. Hope it'll make it into the c++23

Raspredval
Автор

I have custom literals in my codebase for exactly this. I called them _size_t and _ssize_t. I'm glad they're going to be a standard.

ruadeil_zabelin
Автор

This will fix one of the most annoying things in my day-to-day C++

LesleyLai
Автор

I missed the "literals" part of the title when i saw the video notification. Now, it makes more sense!

bettkitty
Автор

It should have been in c++17 already. What took so long :)

afborro
Автор

confused: size_t is already unsigned, why is there an unsigned qualifier? ptrdiff_t is accepted as the signed counterpart to size_t. The z and t format specifiers are already accepted in printf() since C++11.

I suppose since size_t is implementation-defined, some perverse implementor could decide on a type that allows negative sizes?

treyquattro
Автор

Not the same, but related: working with Qt and the standard library in the same project (so basically every Qt project), with any sort of sensible set of warnings enabled your code is covered in static_casts to and from int and size_t :(. (That are no doubt hiding lots of subtle bugs when containers get large.)

timangus
Автор

What am I missing? Why would someone want to use auto on the lhs and then explicitly name the type on the rhs?

yrtepgold
Автор

It seems like given the current revision the EWG accepted z/zu but rejected t/tu, so we're getting one but not the other? Rather curious choice since I think there will definitely be confusion as to why z != ptrdiff_t, even if the paper does justify why that is the case.

hkmix
Автор

Hello Jason! I am a big fan of C++ Weekly, it has helped me learn so much more about C++ than I had ever hoped to know.
I am just wondering if you ever covered C++20 modules? I can't seem to find a video when searching, and while I have had a look at what cppreference has about modules your videos often go into the small details that are easy to miss and give great examples.

vdvman
Автор

Very useful. Allows using `auto` everywhere like `let` in Rust.

nivo
Автор

Great content! However the animations between cuts are a bit wordarty ;)

petermuller
Автор

could you please provide the url of the site which you referred to @31 secs ?

praveerroshan
Автор

FINALLY. I am so tired of having to use size_t instead of auto in variable declarations when working with STL collections and manual algorithms.

vorpal
Автор

Jason, what's your favorite C++ feature?

pendergastj
Автор

size_t can be kinda evil if one's not careful cross compiling between 32/64 bits. Always storing the result of .size() into a uint64_t is the simplest way to be sure I won't mess up. Also what's wrong with: auto val = (uint64_t)myvec.size(). I only use uint[size]_t s to store integers.

DamianReloaded
Автор

is size_t becoming a language feature then? i.e. a keyword instead of a typedef

jbar
Автор

Why is that considered a 'core language feature'? For me it looks like some user-defined literals which can be provided by the STL.

stertingen
Автор

What about that all this types are aliases. It gets really nasty if they map to different integer types on different platforms. Like this long long vs long problem. Every time I explain it to novices they ask me way the int32_t is an alias to int not the other way around. Maybe it was a smart idea in the seventies but today it is a bug source. 😏 With modules they should provide a sane integer behavior which you can opt in per file. 😉

marco
Автор

Nice video. What would be the use case of an unsigned size_t do you think?

Edit: oops I meant signed size_t

adamshield