Skip to content

How to create a string key at runtime? #143

@jgm-ktg

Description

@jgm-ktg

Here is non-frozen code. I need the key being looked up to come from data outside the program... i.e. not a literal. Does frozen do this or does it not solve that gperf-like problem?

        std::unordered_map<std::string_view, int> m = {
                        {{"even_length",11},0},
                        {{"length",6},1},
                        {{"maybe",5},2},
                        {{"symbol",6},3},
                        {{"space_to_nonspace",17},4}
                        };
        std::string line;
        std::getline(std::cin, line);
        fprintf(stderr,"%s\n", line.c_str());
        
        fprintf(stderr,"%.*s index: %d\n", (int)line.length(), line.c_str(), m.at({line.c_str(),line.length()}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions