Hypercursed generalization to types of arbitrary size: compute a constexpr hash and pray for no collisions.
=> More informations about this toot | View the thread
Here's a fun little trick to allow pattern matching on slightly (slightly) more complex types in C++:
struct Type
{
bool a = false, b = false;
enum class [[clang::enum_extensibility(open)]] Case { };
constexpr operator Case() const { return static_cast<Case>(int(a) + 2*int(b)); }
};
[#]include
using namespace std;
int main(int, char**)
{
Type x { true, false };
switch (x) {
case Type { false, false }: cout << "ff" << endl; break;
case Type { false, true }: cout << "ft" << endl; break;
case Type { true, false }: cout << "tf" << endl; break;
case Type { true, true }: cout << "tt" << endl; break;
}
}
Potentially works for anything you can encode in up to 64 bits. It'll try to implicitly convert to any type that's switchable upon; using a bespoke enum class means the implicit conversion hopefully won't fire in other circumstances where we don't want that. The [[clang::enum_extensibility(open)]] line noise is just to keep Clang from remarking upon what's happening.
Truly horrifying language.
=> More informations about this toot | View the thread
Today's brainwave:
The bikeshedding phenomenon is (in part!) a manifestation of the "Buridan's ass" (so-called) paradox. The smaller the difference is between the distance to two piles of hay, the more effort the ass needs to determine which one is closer. So too with small differences between the quality of different choices of names and syntax. https://en.wikipedia.org/wiki/Buridan%27s_ass
=> More informations about this toot | View the thread
=> This profile with reblog | Go to glaebhoerl@discuss.systems account This content has been proxied by September (ba2dc).Proxy Information
text/gemini