Experimental browser for the Atmosphere
I really like the syntax of our Java DataFixerUpper library, so I tried replicating something similar in C++ with full compile-time support and I'm very happy with what I've landed with: struct foo { int a; unsigned int b; char c; }; static constexpr auto […]
Feb 21, 2025, 2:32 PM
{ "cid": "bafyreia5htyadggwjzoclqewqf36seawin3v5rl7ywye3nyqnd3gd4swr4", "uri": "at://did:plc:f66dkdmphqw54y5wovv4j5z3/app.bsky.feed.post/3liozjcapp4l2", "value": { "$type": "app.bsky.feed.post", "bridgyOriginalText": "<p>I really like the syntax of our Java DataFixerUpper library, so I tried replicating something similar in C++ with full compile-time support and I'm very happy with what I've landed with:</p><pre><code>struct foo {\n int a;\n unsigned int b;\n char c;\n};\n\nstatic constexpr auto foo_codec = tuple_codec(\n varint_codec<int>.of_member(&foo::a), // zig-zag + varint encodes\n unsigned_int_codec.of_member(&foo::b),\n char_codec.of_member(&foo::c)\n).apply<foo>(); // Applies default ctor\n\nconst auto str = foo_codec.encode(foo{-1234, 0xbeefu, '@'});\nconst auto foo = foo_codec.decode(str);\n</code></pre><p>Internally this uses <code>std::tuple</code> to apply a series of callables in either direction for encoding and decoding</p>", "bridgyOriginalUrl": "https://retrodev.social/@xilefian/statuses/01JMMESQZYDGE03DPDTBWAWCK8", "createdAt": "2025-02-21T14:32:47.000Z", "embed": { "$type": "app.bsky.embed.external", "external": { "$type": "app.bsky.embed.external#external", "description": "", "title": "Original post on retrodev.social", "uri": "https://retrodev.social/@xilefian/statuses/01JMMESQZYDGE03DPDTBWAWCK8" } }, "langs": [ "en" ], "text": "I really like the syntax of our Java DataFixerUpper library, so I tried replicating something similar in C++ with full compile-time support and I'm very happy with what I've landed with:\n\n\n struct foo {\n int a;\n unsigned int b;\n char c;\n };\n\n static constexpr auto […]" } }