-1

I've looked for it but I've not been able to find a solution. Sorry it this has been already posted.

I have to create a stxxl::map structure mapping const char* into const char* (the optimum would be string into string but I am aware stxxl containers don't accept non POD)

I have a problem defining the comp_type structure for const char*. Has anybody an example of that?

Here's the one that I wrote:

struct comp_type : public std::less<const char*>
{
        static int max_value()
        {
                return (std::numeric_limits<char>::max)();
        }
};
  • Change `static int max_value()` to `bool operator ()(char const* const) const`, return a `bool` instead of an `int`, and don't inherit from `std::less<>`. And -1 for not investigating how comparison functors for the standard library work in general -- many sites explain this in detail. – ildjarn Mar 17 '12 at 03:28

1 Answers1

1

I don't have enough reputation to comment yet. So I am posting a reply.

@ildjarn: With stxxl you need static T min_value() and static T max_value() in certain cases.

@Fabrizio: Are you sure you want to compare two const char*s directly? Which is what you are doing by inheriting from std::less<const char*>. If your intention is to compare two strings you'll need something like this,

struct comp_type : public std::binary_function<const char*, const char*, bool>
{
    bool operator ()(const char* left, const char* right)
    {
        return strcmp(left, right) < 0;
    }

    static const char* min_value() { return "\0"; } // I hope this is the minimum

    static const char* max_value() {...} // I don't know of any maximum value
};

Note that it is static const char* max_value() and not static int max_value(). Hope this helps.

Hindol
  • 2,924
  • 2
  • 28
  • 41