CT Busy Beaver

Ali Çehreli acehreli at yahoo.com
Sun Aug 19 09:37:52 PDT 2012


On 08/19/2012 04:44 AM, bearophile wrote:

 > Most of your code is very similar to mine, but I can also see many
 > little differences, so it seems you have written your translation from
 > scratch.

Yes, I've decided to start from scratch. I did look at yours after 
struggling for some time and I was surprised to see how much 
similarities there were between yours and mine.

Especially the 'static assert(false)' trick: Both you and I have thought 
about using. Those were helpful in solving the two linker errors (which 
maybe what you have experinced too).

The calls inside main() were being resolved to the D-equivalent of this 
struct template (I don't have the D-equivalent anymore):

template<typename T>
struct type_list_to_vector {
     void operator()(std::vector<int> &output);
};

And of course because there was no definition, the linker was 
complaining. I saw that only after implementing the above operator() as 
an opCall() that contained only a single 'static assert(false)'.

Then, I saw my mistake: The Head template parameter had to be 'int' (not 
type).

 > In your code you have left the original C++11 naming conventions:
 > struct step(Direction d, Left, Right) {
 >
 > But in D it's better to write:
 > struct Step(Direction d, left, right) {

Absolutely. I've decided to make as little changes as needed.

 > In type_list_to_vector you have solved the problems in a simple way and
 > using a quite different way.

It is interesting and problematic that I could not replace the following 
two lines:

         type_list_to_vector!Tail tl2v;
         tl2v(output);

With the following line (which is closer to the C++11-original) even 
before or after defining a 'static opCall()':

         type_list_to_vector!Tail()(output);

Error: function 
deneme.type_list_to_vector!(repeat!(0)).type_list_to_vector.opCall (ref 
int[] output) is not callable using argument types ()

I thought that it was a bug that the compiler does not construct an 
object and call opCall() on it. (Note: I now suspect that the opCall() 
being non-const could be the problem; but I still could not make it work.)

 > Thank you,
 > bearophile

Thanks for the challenge,
Ali



More information about the Digitalmars-d-learn mailing list