Why is c++ type inference so shit?

why is c++ type inference so shit?

Attached: 1655693299261.png (830x203, 26.15K)

I wouldn't judge use if you used simple ol' C. I would've judge you if you're using C++ for /gay/mes.

Otherwise i would judge you for not using superior Rust.

>. I wouldn't* judge you if you're using C++ for /gay/mes

i wouldn't use it for anything
>superior Rust.
i agree, haven't really used it much because i don't really know what to make

sepples is such an atrocity
captcha: MVKHV

>why is c++ [...] so shit
Yes.

What's wrong with game develop-
>superior Rust
Ah, I see why you hate it so much now. Maybe in one more year and two more weeks Rust will take over amirite?

I don't use c++ but not getting why would you expect auto to resolve to short here? 0 is an int literal unless otherwise specified. There isn't any other language with type inference that you would reasonably expect to give you a short here. Feel free to provide examples that prove me wrong, however.

>declare i as an int
>wtf why does the compiler think it's an int

are all rustrannies this retarded?

I prefer C++'s simple bottom up algorithm. I don't see the benefit to letting type information flow in arbitrary directions from nodes that are arbitrarily far away. I like being able to simply ask "what's the type of this" with decltype.
Just write short i. It's more readable anyway.

all binary operations in C/C++ are promoted to at least 32-bit, (short)5 is compiled as (int)(short)5 for comparison

the first instance of i is assigned an int the error is correct

Attached: Screen_Shot_2021-02-17_at_2.52.46_PM.png (694x402, 91.34K)

i < (short)5


sweetheart just do
for (std::uint16_t i = 0; i < 5; ++i) { ... }

why is op's intellect level is so shit?

i < (short)5 is irrelevant.
decltype(0) is an int, thus auto i = 0 will result in i being an int.

just install D
void main()
{
import std.stdio: writeln;
import std.conv: to;
import std.range: iota;

static foreach(i; iota(1,5)) i.to!short.writeln;
}

disgusting

you can have your parens if you want. i.to!short.writeln();
if you don't like UFCS, you can also do writeln(to!short(i) );
But im not sure why you would.
Unless it's the template instantiation of to!Type, then that's just a case of you baby ducking honestly.

What's the problem? int and short are distinct types, one is not a subtype of the other.

Rust:
fn main() {
let mut i = 0;
while i < 5_u16 {
i += 1;
assert_eq!(std::any::Any::type_id(&i), std::any::TypeId::of::());
}
}
An integer literal looks ahead to see how it's used. If possible it uses that to infer its type (otherwise it defaults to i32).
You can even do things like this:
fn i_want_an_ip_address(addr: std::net::IpAddr) {}

fn main() {
let s = "0.0.0.0";
let addr = s.parse().unwrap();
i_want_an_ip_address(addr);
}
.parse() looks ahead, sees that it has to return an IpAddr, and calls the correct implementation instead of e.g. trying to parse an integer or a mime type or what have you.
There are other languages with more sophisticated type inference than Rust's, though I don't know how many of them extend that to integer literals. C++'s is very primitive.
This sort of inference can lead to accidental backward compatibility breaks, so it's not all great. Adding a new function or trait implementation (read: overload) might cause existing code to become ambiguous and type inference to fail. It doesn't happen often but it's worrying.

>assert_eq!(std::any::Any::type_id(&i), std::any::TypeId::of::());
i love that every r*st post looks like a shitpost

I sometimes post really grotesque Rust code on purpose (like , sadly the thread got deleted), but is this one that much worse than static_assert(std::is_same_v)?

Attached: Screenshot 2022-06-20 at 13-39-12 _g_ - Technology ยป Thread #87399416.png (431x735, 25.61K)

>auto i = 0
>0 is an int literal
>auto gets deduced as int
>NOOOO SAVE ME NIGGERMAN I'M GONNA DILAAATE

The "rust trannie" thing is seriously old. It's mainly just people who want something better than C++. But that said, I will never use Rust because in my uninformed opinion C++ is way better. The C purism meme on Any Forums is the worst (psychometric profile - autism and OCD).