Untitled

?

Attached: &.jpg (596x155, 24K)

Other urls found in this thread:

godbolt.org/g/5Xokpk
twitter.com/SFWRedditImages

C++ is ugly.

First one is more readable, but second one is more consistent with other uses of const. I use the first one since it matches 90% of uses of const.

std::string const& s is better because it's logical. You get a reference to a const string. Otherwise it's ambiguous and shit and you shouldn't write like that.

fn foo(s: &str)

>Troll

based

What the fuck is this shit

int main(int argc, const char const*const*const argv);

Rust

no voids

>t. constgirl

It's not a troll. I think C++ is one of the ugliest looking languages.

blame C for such shitty type declarations. c++ at least makes it consistent when using &.

Well, I have to agree there.

fn foo(mut s: &str)
or
fn foo(s: &mut str)

void foo(const std::string &s);

And the first one is a reference to a string that is const.

Both shit

Why don't references use the -> like pointers? That is the one thing I would change about C++
Reference literally means pointer, except not NULL, so it should use the exact same syntax

>Reference literally means pointer, except not NULL
Wrong

Reference is an alias for an object and an actually object itself. A pointer is an object that "points" to another object". Because references are simply an alias, they don't need to be dereferenced first.

>Reference is an alias for an object and an actually object itself.
Whoops, I meant to say this:

A reference is an alias for an object and NOT an object itself

No, it is true. At the compiler level, there is zero difference between a pointer and a reference.
godbolt.org/g/5Xokpk

A reference is NOT an object. A pointer is.

The second function returns a value, not a reference.

would know for raw pointer, but r-value reference? no idea
it should never point to anything else from definition, so one of them is pointless. but which?

Foo(String s)

Attached: narukami.jpg (1920x1080, 584K)

Yes. Do you understand the example? Getting the value of a reference is the same as dereferencing a pointer. A reference is a pointer but with difference syntax, and the requirement that it cannot be NULL

nope turned out there are equal, the content of s is constant

Yes, but a reference isn't an object.

nice, under what license did you post it here?

Sorry, what is that supposed to mean/what difference does it make?

>string&
>const&
you know idiots that the var is a reference not the type
>&s
what if someone wrote
>int& i,j,k,l;
let's hunt the reference.
>You get a reference to a const string
>std::string const& s is better because it's logical
you see the string first, you say const.
then you see the const, you say string.
let's call it const string and declare it backwards,
because it's logical.

void poo(auto loo);


But really,
void poo(const std::string &loo);

Are you not supposed to point out that every reference is const and that the const in the second option is completely useless?

One of these things is not like the other.

Your opinion was noted and discarded

No, they're exactly equivalent.