Getting rid of callbacks


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.



Popular posts from this blog

September release of or-tools

Changing the way we link with SCIP

Heads up, upcoming incompatibility in the CP/Routing library