Skip to content

[SUGGESTION] f? and c? types #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
msadeqhe opened this issue Mar 26, 2023 · 7 comments
Closed

[SUGGESTION] f? and c? types #297

msadeqhe opened this issue Mar 26, 2023 · 7 comments
Assignees
Labels

Comments

@msadeqhe
Copy link

msadeqhe commented Mar 26, 2023

Currently the following type aliases are defined in cpp2util.h:

  • i8, i16, i32 and i64 for various signed integer types
  • u8, u16, u32 and u64 for various unsigned integer types

I propose to also define the following type aliases:

  • f16, f32, f64 and f128 for various floating-point types

Also this can be done for char?_t types, but I'm not sure if it is common:

  • c8, c16 and c32 for various character types
@leejy12
Copy link

leejy12 commented Mar 26, 2023

I wish to also have isize and usize types.

isize is equal to std::ptrdiff_t and usize is equal to std::size_t.

@JohelEGP
Copy link
Contributor

JohelEGP commented Mar 26, 2023

isize is equal to std::ptrdiff_t and usize is equal to std::size_t.

C++23 has z and uz (https://en.cppreference.com/w/cpp/language/integer_literal).

@JohelEGP
Copy link
Contributor

I propose to also define the following type aliases:

* `f16`, `f32`, `f64` and `f128` for various floating-point types

C++23 has those, and bf16 (https://en.cppreference.com/w/cpp/types/floating-point). According to https://en.cppreference.com/w/cpp/compiler_support, GCC and MSVC implement the feature (there are two rows, one in the language and another in the library). MSVC doesn't implement any of the optional types. It's not clear what GCC provides or not.

@AbhinavK00
Copy link

Cpp has those as literal suffices, I guess the proposal is for types to have those names

@hsutter
Copy link
Owner

hsutter commented Apr 2, 2023

  • f16, f32, f64 and f128 for various floating-point types

I've been tempted to add these, but only GCC currently supports <stdfloat> (and even then those aliases are optional so I'd have to repeat those feature test macros)... There's value in providing these if it can be done portably though, so when the C++23 things are not available, is there a robust (i.e., well-known and well-used) and reasonably portable fallback to define them?

  • c8, c16 and c32 for various character types

I'd worry that means wading into the Unicode swamp and having to decide what of several things c16 would mean... 😬 taking that on right now feels like a distraction...

@hsutter hsutter self-assigned this Apr 2, 2023
@hsutter hsutter added the question - further information requested Further information is requested label Apr 2, 2023
@msadeqhe
Copy link
Author

msadeqhe commented Apr 4, 2023

I'd worry that means wading into the Unicode swamp and having to decide what of several things c16 would mean... 😬 taking that on right now feels like a distraction...

Infact I was thinking about "text"<c8> (Literal Templates) when I wrote this suggestion 😀.

@hsutter
Copy link
Owner

hsutter commented Apr 9, 2023

Thanks again... I haven't seen much more discussion since adding the further-info-request label for this question:

There's value in providing these if it can be done portably though, so when the C++23 things are not available, is there a robust (i.e., well-known and well-used) and reasonably portable fallback to define them?

So I'll close this issue for now, but please reopen with a PR when someone can provide a way to do it the above way and enable it to be a robustly portable feature. Thanks!

@hsutter hsutter closed this as completed Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants