Skip to content

How to create a string key at runtime? #21

Description

@Randalphwa

Migrated from the original repository
Original issue: serge-sans-paille/frozen#143
Originally reported by: @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()}));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions