dropbox / djinni

A tool for generating cross-language type declarations and interface bindings.
Apache License 2.0
2.88k stars 488 forks source link

Write operator functions for custom struct or class generated by djinni #448

Closed Mazenak closed 4 years ago

Mazenak commented 4 years ago

Hi, I'm facing a problem with the operator functions. I've created a custom class by djinni and it's generated as follows:

struct myClass final {
    /**myClass id */
    int32_t id;
    /**myClass name */
    std::string name;
    /**myClass code */
    std::optional<std::string> code;

    myClass(int32_t id_,
            std::string name_,
            std::optional<std::string> code_)
    : id(std::move(id_))
    , name(std::move(name_))
    , code(std::move(code_))
    {}
    myClass(){}
};

and I need to create a set of it, so I need to implement custom operator. what is the way to do it with djinni ? what is the best practice for this cases ?

Thanks

tonygrue commented 4 years ago

For questions about best practices or how to achieve something, I'd suggest asking in the MobileCpp Slack community which is referenced in the REAME.md; you'll probably get a much faster response there, since this repo doesn't have active maintainers.

artwyman commented 4 years ago

What operators do you need? Generated records will get comparison operators if you enable it via deriving (eq, ord), which should let you use std::set. Custom std::hash are also generated when necessary, so you can use std::unordered_set.