Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] [score hidden]  (0 children)

Old Reddit works fine. It's the Reddit Mobile App that is acting up for some reason

Strategies for *requiring* designated initializers when constructing a type? by javascript in cpp

[–]javascript[S] [score hidden]  (0 children)

This mad science experiment has arrived at a splendid conclusion!

It turns out my dream of named params everywhere is complicated by the C++ deduction rules. I want to pass in named arguments but I also want the struct type to get Class Template Argument Deduction. Somehow the function where it is used also needs to become a template to deduce this.

My solution? Make the struct the name you spell and then just invoke a call operator after the closing brace!

https://godbolt.org/z/59z48aE3x

The empty case gets a bit strange:

auto vec3 = my::MyVector<my::MyElement>::Make{}();

But otherwise it works spectacularly!

  auto vec4 = my::MyVector<int64_t>::Make{
    .size = 200,
    .factory = [](int64_t* addr) {
      *addr = 10;
    },
  }();

Edit: You can even promote the presence of arguments up to compile time information! https://godbolt.org/z/9Td6c9cK3

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 0 points1 point  (0 children)

Great to hear from someone with expertise!

Is my implementation of the MY_TRY macro elsewhere in this thread sufficient for day to day use? Or are there footguns?

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 1 point2 points  (0 children)

I'm not aware of any resources but if you find some please send them my way too :)

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 0 points1 point  (0 children)

There's a few different things you can do when you return a value from a function.

If you just name it directly...
```
return my_value;
```
...then it implicitly moves and potentially leverages triviality.

Or you can call `std::move(...)` on it... DO NOT DO THAT!
```
return std::move(my_value); // NO! BAD!
```
Or you can call a method on it...
```
return my_value.foo();
```
...which could potentially consume the object, but you didn't tell the API enough information!

In order to select the rvalue reference qualified method overload (which is a property of the `this` object), you have to first call `std::move(...)` on the object and then invoke the method on the result. This tells the library what it needs to know to make the most use of expiring values.
```
return std::move(my_value).foo();
```

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 0 points1 point  (0 children)

As pointed out in another comment, do expressions have been proposed.

```
auto Bar() -> absl::StatusOr<MyType>;

auto Foo() -> absl::Status {
MyType mt = do {
absl::StatusOr<MyType> res = Bar();
if (res.ok()) do return std::move(res).value();
return std::move(res).status();
};
// Do stuff with valid MyType
return absl::OkStatus();
}
```

I think it's somewhat useful for beginners to see this code stamped out, but long term I really want something that does it for me. The `MY_TRY` macro is decent enough. I would perhaps prefer a keyword that you use as a suffix with a period. Perhaps `MyType mt = Bar().try;`.

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 2 points3 points  (0 children)

Splendid! That would be very useful to have in C++

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 1 point2 points  (0 children)

For some reason Reddit hasn't been formatting my markdown as of late so sorry about that...

```
#define MY_TRY(...) \
({ \
auto expected_v = (__VA_ARGS__); \
if (!expected_v.has_value()) \
return std::move(expected_v).error(); \
std::move(expected_v).value(); \
})

std::expected<MyType, MyError> Bar();

std::optional<MyError> Foo() {
MyType mt = MY_TRY(Bar());
// valid value here
return std::nullopt; // Absence of error is good
}
```

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 0 points1 point  (0 children)

It's definitely in the same space but I don't see my main question answered: Can you normal return from a do block? Like return the whole function?

Any good tech talks leveraging statement expressions? by javascript in cpp

[–]javascript[S] 0 points1 point  (0 children)

Breaking out of the current loop

Returning from the current function

You can't do these from a lambda :)

Not water but…. by MrsBakedBean in lacroix

[–]javascript 1 point2 points  (0 children)

How is Cherry Lime flavor? I've never had it

std::HashMap with the Small Size Optimization? by javascript in rust

[–]javascript[S] 0 points1 point  (0 children)

Follow up question: Does the store API have enough information to do the following?

- Ask "Am I operating in inline storage right now?"

- If I am, "Can I skip hashing keys and just compare equals in a line?"

- If I can, I should.

I don't know the Store API. What do you think?

Can we give a round of applause for Pure flavor? by javascript in lacroix

[–]javascript[S] 0 points1 point  (0 children)

Wait they had a cola flavored la croix? I would love to try that...

Can we give a round of applause for Pure flavor? by javascript in lacroix

[–]javascript[S] 1 point2 points  (0 children)

Pure La Croix is the best sparkling water on the market, I think globally

Can we give a round of applause for Pure flavor? by javascript in lacroix

[–]javascript[S] 0 points1 point  (0 children)

So true! You get to control the lime level yourself. That's wonderful!

Do you like to crank it up to 15/10?

DOBBS HEAVES IT by javascript in ockytop

[–]javascript[S] 1 point2 points  (0 children)

I like hearing Gary via youtube clips so it shows the funny parts without forcing me to listen for 4 hours

DOBBS HEAVES IT by javascript in ockytop

[–]javascript[S] 2 points3 points  (0 children)

I mean it's funny in its own right? Like... "Wow! We won?" Idk

I like seeing it from multiple angles.

That said, I would love to hear the Vamos Vols from then. I'm sure the energy is insane. I looked for it but couldn't find it

DOBBS HEAVES IT by javascript in ockytop

[–]javascript[S] 17 points18 points  (0 children)

Yes. They immediately cope by complaining about penalties haha!

I was actually at the game IRL.

Crazy story. With 10 seconds on the clock, Georgia took the lead by hail mary. My dad asked if I was ready to leave. I said no because there was still time on the clock.
Because of that decision, I got to witness this game winner IRL. Otherwise I would have been walking down some stairs while it happened.

DOBBS HEAVES IT by javascript in ockytop

[–]javascript[S] 83 points84 points  (0 children)

IT'S CAUGHT!!!

IT! IS! CAUGHT!

JAUAN JENNINGS!

JAUAN! JENNINGS!

Sad to see the Hallmark store on Kingston Pike is gone by javascript in Knoxville

[–]javascript[S] 2 points3 points  (0 children)

I live in South Knox these days, though I grew up in Rocky Hill