simontoth, to cpp
@simontoth@hachyderm.io avatar

When working with exceptions in C++, there are three main levels of guarantees a function can provide when an exception is thrown.

🧵👇

Compiler Explorer link: https://compiler-explorer.com/z/T9YKKa5oW

#cpp #cplusplus #coding #programming #dailybiteofcpp

simontoth, to cpp
@simontoth@hachyderm.io avatar

The std::forward is a conditional r-value (specifically x-value) cast.

std::forward is primarily designed to work in conjunction with universal references and will only cast to an r-value if the template argument isn't an l-value reference type.

Compiler Explorer link: https://compiler-explorer.com/z/E5dcPh6T3

simontoth, to cpp
@simontoth@hachyderm.io avatar

C++20 introduced a set of safe integral comparison functions that can compare different integral types without introducing accidental conversions.

Compiler Explorer: https://compiler-explorer.com/z/3Phjhrcqv

simontoth, to cpp
@simontoth@hachyderm.io avatar

📆 Day 21 of Advent of Code 2023 is here. Today, we are counting reachable spaces.

🧐 Very sneaky problem today (specifically part two).

🤓 Maths to the rescue.

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-day-f73?r=1g4l8a&utm_campaign=post&utm_medium=web

simontoth, to cpp
@simontoth@hachyderm.io avatar

📆 Day 18 of Advent of Code 2023 is here. Today, we are digging out a lava duct.

🤯 Part two today was a horrible debug-fest for me.

😋 Anyone who found part two easy? 😅

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-day-e9d?r=1g4l8a&utm_campaign=post&utm_medium=web

simontoth, to cpp
@simontoth@hachyderm.io avatar

📆 Day 7 of Advent of Code 2023 is here. Today, we are analyzing "Poker" hands.

😴 I have to apologize for laziness today. I went the easy route.

🤔 Did you take the time to come up with a fancy encoding to analyze the hands?

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-day-078?r=1g4l8a&utm_campaign=post&utm_medium=web

simontoth, to cpp
@simontoth@hachyderm.io avatar

📆 Day 2 of Advent of Code 2023 is here. Today, we are parsing information about cubes.

😱 Did you struggle with the parsing?
😉 What was your approach?

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-day-e49?r=1g4l8a&utm_campaign=post&utm_medium=web

simontoth, to cpp
@simontoth@hachyderm.io avatar

C++20 introduced the <bit> header with a group of functions for manipulating and querying bits in unsigned integers.

These functions were previously only available as compiler extensions.

Compiler Explorer link: https://compiler-explorer.com/z/qEWzzcfv9

simontoth, to cpp
@simontoth@hachyderm.io avatar

Tuesday common C++ interview problem: O(1) region sum.

Given a 2D grid of integers, provide a method that calculates the sum of a sub-region:

  • int64_t Grid::region_sum(Coord top_left, Coord bottom_right) const;

The methods must operate in O(1). You are allowed preprocessing and O(|grid|) memory.

Solve it yourself: https://compiler-explorer.com/z/nxvqrqfWq
Solution: https://compiler-explorer.com/z/31GMbscxT

simontoth, to cpp
@simontoth@hachyderm.io avatar

The C++23 standard introduced a monadic interface for std::optional<T>.

  • transform(f(T)->U)->std::optional<U>

only invoked when the source isn't empty

  • and_then(f(T)->std::optional<U>)->std::optional<U>

only invoked when the source isn't empty

  • or_else(f()->std::optional<T>)->std::optional<T>

only invoked when the source is empty

Compiler Explorer link: https://compiler-explorer.com/z/4dzc776Gq

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • rosin
  • InstantRegret
  • ethstaker
  • DreamBathrooms
  • mdbf
  • magazineikmin
  • thenastyranch
  • Youngstown
  • everett
  • slotface
  • osvaldo12
  • khanakhh
  • kavyap
  • anitta
  • Durango
  • vwfavf
  • GTA5RPClips
  • cubers
  • tacticalgear
  • tester
  • cisconetworking
  • ngwrru68w68
  • Leos
  • normalnudes
  • provamag3
  • modclub
  • JUstTest
  • All magazines