Getting rid of callbacks

Hello,

with C++11 now correctly supported by compilers, we are in the process of removing callbacks, and replacing them with std::function<>.

We have reached a good milestone where the constraint programming library is migrated, except the routing library.

For instance:

Solver::MakeElement(ResultCallback1(int64, int64) values, IntVar* index)

is now

Solver::MakeElement(std::function<int64(int64)> values, IntVar* index)

Unfortunately for me, this impacts the other languages:
Python is unchanged, thanks to swig magic.

java is impacted. Previously, you needed to subclass LongResultCallback1 to implement the values in the element expression. Now, you need to subclass LongToLong. The API is the same.
LongResultCallback1/2/3 are kept for the routing library.

C# follows the same road. You also need to subclass LongToLong to use the element expression.

Here is the list of base classes for callbacks in Java and C#. The virtual method is called run in java and Run in C#.

  • IntIntToLong
  • LongLongLongToBoolean
  • LongLongLongToLong
  • LongLongToLong
  • LongToBoolean
  • LongToLong
  • LongToVoid
  • VoidToBoolean
  • VoidToString
  • VoidToVoid
I agree this breaks compatibility, but using functions is so much nicer than our own supplied callbacks.

Thanks

Comments

Popular posts from this blog

Heads up, upcoming incompatibility in the CP/Routing library

Documentation: new examples and reference manual

Changes in the last month - on windows this time