Calypso: Direct and full interfacing to C++

Kelly via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Feb 8 20:27:04 PST 2015


On Sunday, 8 February 2015 at 22:45:14 UTC, Elie Morisse wrote:
> On Sunday, 8 February 2015 at 20:56:31 UTC, Syro wrote:
>> That is really cool.
>
> Thanks, just got that tangled mess of templates that is 
> std::string working too:
On Sunday, 8 February 2015 at 22:45:14 UTC, Elie Morisse wrote:
> On Sunday, 8 February 2015 at 20:56:31 UTC, Syro wrote:
>> That is really cool.
>
> Thanks, just got that tangled mess of templates that is 
> std::string working too:

Hey Elie, this is great stuff, as usual. I have written a test 
file for bitset here also (including a couple failures I am sure 
you are aware of, but others might want to see what works and 
what doesn't).


/**
  * std::bitset example.
  *
  * Build with:
  *   $ ldc2 -L-lstdc++ bitset.d
  */

modmap (C++) "bitset";

import std.stdio;
import (C++) std.bitset;

void main()
{
     enum : ulong { A=0, B, C, D, E, F, G, H, numColors };
     auto usedColors = new bitset!(numColors);

     usedColors.set(A, true);
     usedColors.set(C, true);

     writeln("usedColors.len=\t", numColors);   // '8' as it 
should be
     write("usedColors = \t");
     if (usedColors.any())                      // any() works
     {
         for(int i=0; i<usedColors.size; i++)   // size seems to 
work
             if (usedColors.test(i))            // works
                 write('1');
             else
                 write('0');
         write('\n');           // prints 10100000 for usedColors
     }                          // seems backwards also see 'b' 
below
                                // is this right?

     writeln("C bit = \t", usedColors.test(C));      // true as it 
should be
     writeln("count = \t", usedColors.count());      // seems like 
count is
                                                     // 
working...returns 2
     writeln("as ulong = \t", usedColors.to_ulong);  // '5' is 
correct

     writeln("all = \t\t", usedColors.all);
     writeln("none = \t\t", usedColors.none);        // these work
     writeln("any = \t\t", usedColors.any);

     usedColors.flip(C);
     writeln("C flipped = \t", usedColors.test(C));  // false as 
appropriate

     write("b = \t\t");
     auto a = new bitset!(4u)(0b0110);
     auto b = new bitset!(4u)(0b1101);
     for(int i=0; i<b.size; i++)        // size seems to work
     {
         if (b.test(i))
             write('1'); // prints out 1011 for 'b'
         else
             write('0');
     }
     write('\n');
     writeln("b as ulong = \t", b.to_ulong); // '13' is correct

// FAILURE in phobos format.d
//    writeln(b);

// FAILURE because the [] operator isn't recognised
//    writeln(usedColors[C]);

// FAILURE on operators again
//    auto d = a&b;

}

Thanks,
Kelly


More information about the Digitalmars-d-announce mailing list