You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is possible, and something I've tried to do in hopes of PRing it to PROS, but there's no way of doing it that doesn't risk breaking user code. Luckily, we don't have the issue of backwards compatibility. Here's a proof of concept:
structDynamicPort {};
constexpr DynamicPort runtime_check_port{};
classPort {
public:constevalPort(int64_t port): m_port(port) {
// XXX: this doesnt actaully throw an exception since the ctor // is consteval, it halts compilation insteadif (port < 1 || port > 21) throw"Port out of range!";
}
Port(int64_t port, DynamicPort) : m_port(port) {}
private:uint8_t m_port;
};
classDevice {
public:Device(Port port): m_port(port) {}
private:
Port m_port;
};
intmain() {
Device motor(2);
// this won't compile// Device invalid(22);int i = 22; // read from sd card perhaps// this won't compile// Device rotation(i);
Device rotation(Port(i, runtime_check_port));
}
Overview
User code should not compile if the user tries to pass a port to a sensor that's not valid
Example
The text was updated successfully, but these errors were encountered: