4 ms·
I was trying something in the line of refinement types in C++ to solve the sequential method (anti)pattern, without success. For example, one would have Config
by jcarrano 2y ago
I was trying something in the line of refinement types in C++ to solve the sequential method (anti)pattern, without success. For example, one would have
ConfiguredThing Thing::configure(....) &&;
Where ConfiguredThing and Thing have the exact same members, so doing
auto y = std::move(x).configure(...);
would not copy any data around. It seemed to work with optimizations on, but then there are no guarantees that it will always be the case.
Ideally one would want RAII, but that is not always possible, in particular when wrapping C libraries that may have their own logic. Also, the object could be in different states, with different methods available in each state, and then it would be possible to prevent errors at compile time.
- jcarrano 2y agoOn a second thought, this may be more in the direction of linear types.