@vector-of-bool.bsky.social
C++ librarian, programming blogger, meme enjoyer. I write code and sometimes I actually publish it. Creator of http://bpt.pizza Don't let your memes be dreams!
There is also the "gap" in C syntax where you omit the semicolon in a compound statement:
{ foo; bar; baz }
Which is just a syntax error. Rust fills the "gap" by giving it useful semantics. I think C & C++ could do the same, which may be better than _With, but would be more complex to define.
There is also the "gap" in C syntax where you omit the semicolon in a compound statement:
{ foo; bar; baz }
Which is just a syntax error. Rust fills the "gap" by giving it useful semantics. I think C & C++ could do the same, which may be better than _With, but would be more complex to define.
In my hypothetical, _With would only allow a single subsequent expression (which may be another _With to effectively get a linear sequence of statements)
Not quite like GCC's "statement expression" (gcc.gnu.org/onlinedocs/g...) which allows for arbitrary control flow, like Rust's block expressions.
I almost forgot about this proposal! It's very interesting.
I think you could combine it with a hypothetical _With so that you don't have a dedicated syntax that's only available in using-expressions:
using min_of(auto x, auto y) =
_With(auto X = x)
_With(auto Y = y)
X < Y ? X : Y;
This would also give us simple block-statement expressions, since the _With is just a sequence of statements which can be declarations or plain expressions.
const auto x =
_With (auto r = foo())
_With (frombulate(&r))
_With (log_thing(r))
r.subobject;
And you could finally write a min/max macro that doesn't double-evaluate its operands:
# define MIN_OF(X, Y) ( \
_With( \
auto x = (X); \
auto y = (Y)) \
x < y ? x : y)
While we're on the topic of off-the-cuff language proposals: A "with expression":
_With (<decl-stmts>) <expr>
Which allows you to declare variables for the scope of <expr>, and yields the value of <expr>. Now you can:
const T obj =
_With (optional<T> o = foo())
o ? *o : (return nullopt);
This would allow use of return, break, goto etc. to appear in place of any expression, including the arm of a ternary:
optional<T> o = xyz();
T& t = o ? (*o) : (return nullopt);
Which is even more useful in convenience macros that can expand to control flow constructs in expression positions.
Instead, a Bottom/Never type could be used for all of those keywords, and allow it to implicit-convert to any other type in any situation. This works because the Bottom type is un-constructible, and therefore any conversion from it is unreachable.
26.07.2025 18:31 β π 2 π 0 π¬ 1 π 0"throw" expression has type "void", but has one special case if it is one of the cases in a ternary "?:" expression, where its void is "converted" to the other operand. This is the only situation where this happens, but it could be extended arbitrarily for return, break, continue, and goto.
26.07.2025 18:31 β π 1 π 1 π¬ 1 π 0And do the same for "go-to", while we're at it.
26.07.2025 16:50 β π 1 π 0 π¬ 0 π 0Consider: Attributes on preprocessor macro definitions
\#define [[lol]] foo() bar
I could survive off of these alone. www.costcobusinessdelivery.com/don-miguel-b...
25.07.2025 03:56 β π 1 π 0 π¬ 0 π 0I've played around with writing dedicated mostly-regular never and unit types that have implicit conversions. I probed for issues it might cause and haven't yet found anything concrete, but that might just be my lack of imagination.
Also: std::variant<> should be well-formed.
Also: C&C++ should have a built-in bottom type (`_Never` / `std::never_t`) that's convertible to anything. Encode [[noreturn]] in the type system.
And give us `_Unit` / `std::unit_t`, convertible from anything. Regular-void is just not going to work when `void` tries to be both, and fails at both.
Have there been any proposals to promote C++ (or C) `return` to an expression of bottom type? (like `throw`'s weird "void but special" type)
23.07.2025 22:28 β π 1 π 1 π¬ 2 π 3The good thing about repeatedly reinventing wheels is that you get faster at building wheels and your wheels become better with every iteration. Eventually you're able to hammer-out near-perfect wheels on a whim.
23.07.2025 06:10 β π 3 π 0 π¬ 0 π 0Arguing about paint colors while Republicans bulldoze the bikeshed (and the neighboring nuclear plant) to make room for Dachau v2.0
15.07.2025 20:15 β π 3 π 1 π¬ 0 π 0As usual, the basis of far-right "science" is just a direct inversion of the evidence pyramid: Peer review meta-analysis is less valid than one random study, which is less valid than one random expert's opinion, which is less valid than the anecdotes of my local Homeschooling Parents Facebook Group.
15.07.2025 06:45 β π 2 π 1 π¬ 0 π 0As usual, the basis of far-right "science" is just a direct inversion of the evidence pyramid: Peer review meta-analysis is less valid than one random study, which is less valid than one random expert's opinion, which is less valid than the anecdotes of my local Homeschooling Parents Facebook Group.
15.07.2025 06:45 β π 2 π 1 π¬ 0 π 0And we've hit $500,000 raised for @doctorswithoutborders.org at #SGDQ2025! Thank you all so much!
09.07.2025 02:51 β π 347 π 104 π¬ 5 π 2TIL that scientists and timekeepers have agreed to abandon the leap second within the next decade, hallelujah
07.07.2025 01:03 β π 2 π 0 π¬ 0 π 0Just noticed that Compiler Explorer has a "Real dark" color scheme and I think that all websites should have this colour scheme.
05.07.2025 17:02 β π 0 π 0 π¬ 0 π 0C APIs with threatening auras
linux.die.net/man/3/explai...
C99 challenge:
1. Given an integral l-value expression X of type T, write a preprocessor macro that determines whether T is signed or unsigned.
2. You may assume two's complement signed integer encoding.
3. Avoid evaluating or modifying X.
I've got an almost-solution, but cannot solve point (2)
Re "cover of darkness": I wonder about one factor absent from past mass atrocities: the ubiquity of high definition cameras, even compared to late 2000s.
They'll have a hard time getting away with anything without risking that some disillusioned staff will live stream video from their iPhone.
Is there a consensus that MSVC C++ deciding to ship a stable library ABI was a bad decision? I feel like it has been a disaster.
03.07.2025 18:59 β π 0 π 0 π¬ 1 π 0We already have echoes of this in constexpr std::allocator<T>. Example: Make your log API generic over `template <file_system_api FileSystem>` and now you have a constexpr-ready logging library. Add an `extern template` for the default runtime FS, and users won't even pay the cost of instantiation.
02.07.2025 15:42 β π 0 π 0 π¬ 1 π 0e.g. for code that uses the filesystem: if the caller wants to access the compile-time filesystem, they pass a compiler-generated "compile-time filesystem" object, otherwise they pass the "run-time filesystem" object created at `main()` for the runtime filesystem. Same for logging, network, etc.
02.07.2025 15:42 β π 0 π 0 π¬ 1 π 0