mardi 14 juin 2016

parsing into structs with boolean or enum members with boost spirit x3


If I have a struct:

struct person{
    bool is_male;
    std::string name;
    std::vector<std::string> friends;
}

or

enum class gender_t{male, female}
struct person{
        gender_t gender;
        std::string name;
        std::vector<std::string> friends;
}

how can I parse into this struct using boost.spirit X3? how would a rule look like to parse a string like "alice male bob" and the parser returning a object with name alice, which is male and has one friend bob. How would it look like if the gender is only explicit said if the person isnt female?


Aucun commentaire:

Enregistrer un commentaire