CT Busy Beaver
Ali Çehreli
acehreli at yahoo.com
Sun Aug 19 09:59:00 PDT 2012
On 08/19/2012 07:07 AM, bearophile wrote:
> Ali Çehreli:
>
>> Took me a while! Phew... :)
>>
>> http://dpaste.dzfl.pl/6b362382
>
> I have back-ported your changes to my version, and it works (with few
> improvements, a larger Busy Beaver, etc):
>
> http://dpaste.dzfl.pl/0791bea9
>
> -----------------------
>
> I have also tried to replace your code like this:
>
> struct TypeListToArray(node : Cons!(value, tail), int value, tail) {
> void opCall(ref int[] output) {
> output ~= value;
> TypeListToArray!tail tl2v;
> tl2v(output);
> }
>
> static auto opCall() {
> TypeListToArray!node tl2v;
> return tl2v;
> }
> }
>
> struct TypeListToArray(node : Repeat!value, int value) {
> void opCall(ref int[] output) {
> output ~= value;
> }
> }
>
> import std.array;
> void main() {
> import std.stdio;
> alias TuringMachine!(BusyBeaver2, Repeat!0, Repeat!0) tm;
>
> int[] tape1;
> TypeListToArray!(tm.finalLeft)()(tape1);
> ...
>
>
> With a shorter template like:
>
> template TypeListToArray(Node) {
> static if (is(Node Repeat : Repeat!value, int value))
> enum TypeListToArray = [value];
>
> static if (is(Node Cons : Cons!(value, Tail), int value, Tail))
> enum TypeListToArray = [value] ~ TypeListToArray!(Node.tail);
> }
>
> import std.array;
> void main() {
> import std.stdio;
> alias TuringMachine!(BusyBeaver2, Repeat!0, Repeat!0) tm;
>
> enum tape1 = TypeListToArray!(tm.finalLeft);
> ...
>
> But it's not working. Do you know why?
Here is a reduced code:
template Foo(T)
{
static if (is (T : int)) {
enum Foo = [ T.init, T.init ];
}
static if (is (T : long)) {
enum Foo = [ T.init ];
}
}
void main()
{
enum i = Foo!int;
enum l = Foo!long;
}
Error: template instance deneme.Foo!(int) error instantiating
Works if the two 'static if' blocks are connected with an else:
static if (is (T : int)) {
enum Foo = [ T.init, T.init ];
} else static if (is (T : long)) { // <-- else makes it compile
enum Foo = [ T.init ];
}
>
> Bye,
> bearophile
Ali
More information about the Digitalmars-d-learn
mailing list