3 ms·
There's no way in C++ to _statically_ guarantee that you don't simultaneously have the floating pin handle and the output pin handle. You cannot do it.
by Warwolt 3y ago
There's no way in C++ to _statically_ guarantee that you don't simultaneously have the floating pin handle and the output pin handle. You cannot do it.
- codr7 3y agoI agree, I'm just waiting for someone to explain why I should care; what's the reason to not declare the pin statically as either or? I mean, I could easily come up with a contrived example that Rust can't do as well, but what's the point?
- detaro 3y ago> what's the reason to not declare the pin statically as either or? That for plenty uses cases, pins are not statically either or, but are switched at runtime. (and the article really fails IMHO by not showing that, because doing that while keeping compile-time checks is the hard part, and its limits would be really interesting)
- pjmlp 3y agoYou can do that by creating types for the pins, and using HKT via template metaprogramming when instantiating the classes that hold handles to the pins. It the implementation code pretty? Most likely not, but here we are discussing what is possible, not beauty.