allwpilib icon indicating copy to clipboard operation
allwpilib copied to clipboard

[cpp cmd] Unify various command types into concepts

Open Starlight220 opened this issue 1 year ago • 6 comments

Resolves #5789

Starlight220 avatar Dec 14 '23 15:12 Starlight220

I'm worried about this inflating headers and compile times due to everything becoming a template.

Starlight220 avatar Dec 22 '23 07:12 Starlight220

Would an approach like the Requirements struct work? (Defining a struct with implicit conversions from everything needed?) I think that would allow the functions to remain non-templated.

KangarooKoala avatar Dec 22 '23 18:12 KangarooKoala

We can make the currently-explicit conversions to CommandPtr implicit... Thoughts?

Starlight220 avatar Dec 23 '23 15:12 Starlight220

It probably should be fine, especially since most teams won't need to use ToPtr() (unless for some reason they're upcasting their pointers to Command*, but that probably won't happen).

KangarooKoala avatar Dec 26 '23 01:12 KangarooKoala

I made the changes locally, and it's causing some issues. Maybe we should be consistent on everything being CommandPtr and that's it? To avoid the shenanigans of implicit conversions.

unless for some reason they're upcasting their pointers to Command*, but that probably won't happen

Wdym?

Starlight220 avatar Dec 26 '23 04:12 Starlight220

unless for some reason they're upcasting their pointers to Command*, but that probably won't happen

Wdym?

I might be wrong, but as I understand it, the point of ToPtr() is so that when given a compile-time Command*, the object can correctly be converted into a CommandPtr. (Naively doing CommandPtr(std::make_unique<Command>(std::move(command)) will not properly handle the virtual methods, which I'm guessing is because it just points to the Command part of the object, without the vtable stuff for the subclass, though I might be wrong about that) However, since most users will only deal with their actual command types, CommandPtr(T&&) should use the correct type argument for make_unique, and they won't need to use ToPtr(). I could be wrong about this, though- I only figured this stuff out today.

KangarooKoala avatar Dec 26 '23 05:12 KangarooKoala