Archived

This forum has been archived. Please start a new discussion on GitHub.

slice2freeze and comparison operators for sorting

Hi,

I'm trying to implement my own comparison operator for sorting, using slice2freeze for C++.

My slice2freeze line looks something like:

$ slice2freeze --dict MyMap,MyKey,MyData,sort,myLess MyMap ...<.ice files etc>...

myLess is defined in <mycompare.h>.

The generated MyMap.h/.cpp files look fine and use myLess for comparison, but the problem is that it can't find "myLess" anywhere: I can't work out how to make it #include <mycompare.h>

I managed to work around the problem by creating an empty file called mycompare.ice, in the same directory as mycompare.h. Appending "mycompare.ice" to the slice2freeze line causes MyMap.h to contain "#include <mycompare.h>". Since I don't actually run slice2cpp on mycompare.ice I can keep my human-written mycompare.h (containing the definition of myLess). The empty mycompare.ice is required because otherwise slice2freeze bitches that it can't find the .ice file.

So I'm all up and running now, but this is pretty ugly. What's the intended solution? I couldn't find anything about it in the manual.


Thanks,

Alex

Comments

  • Have a look at Section 6.15 in the manual. I think the --add-header option is what you want.

    Cheers,

    Michi.
  • Oops--for slice2freeze, the same option is documented in Section 39.3.7.

    Cheers,

    Michi.
  • Oh yeah, sorry, that was obvious. I'd skimmed the precompiled header stuff and not read closely.

    One thing: I notice that the header (mycompare.h) is included in the generated .cpp file but not the generated .h file, even though "myLess" is used in the generated .h file (in the template typedef). This means that in order to #include the generated .h file, I have to first #include <mycompare.h>. Perhaps the header should be included in the generated .h file?


    Thanks,

    Alex
  • The primary motivation for adding the option was to allow precompiled headers to be used. I remember thinking about what you suggest at the time but, as you say, the --add-header option already allows you to do what you need by explicitly #including mycompare.h before #including the generated header file. On the other hand, if --add-header were to generate the #include for the .h file, you would be forced to always include the header in both header and source file, but that may not be what's wanted.

    Seeing that the current mechanism can be used to solve the problem, I'm reluctant to make any changes to it. (Of course, if you have use case that can't be addressed sensibly by --add-header, we'll look at this again!)

    Cheers,

    Michi.
  • Seeing that the current mechanism can be used to solve the problem, I'm reluctant to make any changes to it. (Of course, if you have use case that can't be addressed sensibly by --add-header, we'll look at this again!)

    No, the current scenario is perfectly OK for me. I just thought I'd point it out in case it was an oversight.


    Thanks,

    Alex