[gecode-users] Starting with C++

Christian Schulte cschulte at kth.se
Wed Nov 19 11:24:08 CET 2008


Hi Malcolm,

all your questions have a yes as the answer. Having the possibility to
construct variables in an uninitialized state is actually quite useful
(think of just declaring an integer variable without initializing, same
thing). It might not useful during copying but in other situations (in
particular think of an array of variables - such as IntVarArgs - you would
like to pass as an argument, here you definitely do not want to create a
variable first and then overwrite it).

The reason why copying an array is not controlled by a copy constructor but
by an update function is for two reasons: one, historical (because in
earlier versions the constructor would have clashed with other constructors)
and the other uniformity (for some data structures it is not very easy to
define a constructor, but it is easy to have a separate update function).

Cheers
Christian

--
Christian Schulte, www.ict.kth.se/~cschulte/


-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Malcolm Ryan
Sent: Wednesday, November 19, 2008 5:06 AM
To: gecode list
Subject: [gecode-users] Starting with C++

Given that GecodeJ is no longer supported, I'm in the process of  
migrating my code to C++ (and learning C++ in the process).

It seems from my perusal of the examples that the C++ library works  
slightly differently. Whereas in java the copy constructors for spaces  
look like:

   public Queens(Boolean share, Queens queens) {
     super(share, queens);
     n = queens.n;
     q = new VarArray<IntVar>(this, share, queens.q);
   }

in C++ they look like:

   /// Constructor for cloning \a s
   Queens(bool share, Queens& s) : Example(share,s) {
     q.update(this, share, s.q);
   }

The Java code explicitly contructs a new var array from the old. The C+ 
+ code seems to implicitly construct an empty var array and then call  
'update' to copy the old into the new. Is that correct? Does every  
kind of variable have an no-arg constructor? What is the rationale for  
this choice? It seems that it allows you to construct variables in an  
incompletely initialised state. Is that deliberate?

Malcolm

_______________________________________________
Gecode users mailing list
users at gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users





More information about the gecode-users mailing list