News for hackers. Stuff that matters.

dctwin

Important to note that $72bn of that loss is some accounting thing and not really relevant wrt. the solvency of Anthropic
Re:OpenAI Withdraws 3 Math Papers on Friday October 09, 2026 @05:24AM (#50018105)
Cf. Blums speedup theorem for an extreme example of this
Re:A Practical Intuition for C++20 Coroutines on Monday August 24, 2026 @01:11PM (#49422872)
I just want to say that this is a really great article, probably my favourite explanation of cpp coroutines - thank you
Re:Agent swarms and the new model economics on Tuesday July 21, 2026 @08:51AM (#48991687)
Am I reading this right? Opus + Composer did a comparable job to Fable, at ~1/19th the price, and half the LoC?
Re:Sam Altman's home targeted in second attack on Monday April 13, 2026 @01:01AM (#47747794)
The layoffs haven't even really started yet... I'm very worried about the next two years
Re:Compile-time JSON deserialization in C++ on Friday July 12, 2024 @06:49AM (#40944364)
Oh I think I finally groked what you suggested! Something like

template <StringLiteral str> static constexpr Key<str> key

in the class namespace - I think this this would work, but if I understand this correctly, You would need to do like

User user {...}; user[User::key<"myKey">]

Which actually is not so bad...

Re:Compile-time JSON deserialization in C++ on Thursday July 11, 2024 @02:08AM (#40934045)
Whether or not this is useful (I am also not sure), the JSON doesn't need to survive into runtime at all. If you include the JSON, do a bunch of `if constexpr`, and never touch the JSON outside of a constexpr context, it doesn't have to any footprint on your binary. (I'm not sure if #embed will force stuff to stay in your binary even if you never reference it at runtime)
Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @04:27PM (#40931155)
Yes, very true. I noticed that even already at 3dp the floats start to compare unequal. The long double helped but it's not really.

I googled and found two examples of constexpr float parsing repositories, but from the sounds of things, you understand this problem better than I and will have seen them already

Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @11:34AM (#40928086)
You're right to point out that this is really 'first class JSON', rather than the Pydantic/Jackson type thing where the json barely exists and is immediately transformed into your models and classes.

Thanks for reading the article though, that's cool. I am a daw_json_link fan

Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @09:18AM (#40926550)
The opposite 'toString' problem seems harder - I didn't try, but it should be possible now that std::string is constexpr.

I don't think you could parse it with, say, a class that has a std::string member (because of the transience restriction), but perhaps you can use lambdas that capture that string by reference, and call each other as appropriate?

As for exporting that as some sort of compiler artefact for use elsewhere, I am not sure how you would do that...

Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @09:07AM (#40926455)
You can do something similar, no? std::pow is not constexpr (most float stuff is not, presumably due to floating point state) but you can implement 10^x anyway
Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @06:36AM (#40925530)
Despite my writing the article I agree
Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @06:34AM (#40925522)
Thanks for the idea! Yes constexpr std::vector feels like cheating
Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @06:32AM (#40925513)
Yes, the nonconstexpr version does just that, unless I misunderstood your question. See also boost::spirit for a 'big' version of this
Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @06:10AM (#40925396)
Hm - so this would instantiate a variable for each key in the class namespace? I admit I haven't seen anything like this but sounds very interesting
Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @05:58AM (#40925329)
I was able to do the primitive

long double result = 0.0;

while (...) {

  if (json[head] == '.') ...

  result *= 10; result += json[head] - '0';
}

in a constexpr function with no problem :)

Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @05:51AM (#40925285)
Yes, I agree. I don't see much practical use in this. I was just surprised how (relatively) straightforwards this is to do, and thought it was more cool than useful
Re:Compile-time JSON deserialization in C++ on Wednesday July 10, 2024 @05:49AM (#40925269)
Thank you!
Re:Compile-time JSON deserialization in C++ on Saturday July 06, 2024 @05:35AM (#40889273)
Hello! I wrote this short blog post about using pattern-matching-like template metaprogramming to deserialize JSON at build time - please let me know what you think (especially if you see improvements)