I am getting the following error:
braced initialization of a variable declared with a placeholder type but without `=` requires exactly one element inside the braces
const auto temperature_units{
{"K", [] (double x)->double {return x;}},
{"C", [] (double x)->double {return x+273.15;}},
{"\u2103", [] (double x)->double {return x+273.15;}}, // degree celcius symbol
{"\u00B0C", [] (double x)->double {return x+273.15;}}, // degree symbol plus C
{"F", [] (double x)->double {return (x+459.67)*5.0/9.0;}},
{"\u2109", [] (double x)->double {return (x+459.67)*5.0/9.0;}},// degree fahrenheit symbol
{"\u00B0F", [] (double x)->double {return (x+459.67)*5.0/9.0;}}
};
Something like
const std::map<std::string, auto> temperature_units{
{"K", [] (double x)->double {return x;}},
{"C", [] (double x)->double {return x+273.15;}},
{"\u2103", [] (double x)->double {return x+273.15;}}, // degree celcius symbol
{"\u00B0C", [] (double x)->double {return x+273.15;}}, // degree symbol plus C
{"F", [] (double x)->double {return (x+459.67)*5.0/9.0;}},
{"\u2109", [] (double x)->double {return (x+459.67)*5.0/9.0;}},// degree fahrenheit symbol
{"\u00B0F", [] (double x)->double {return (x+459.67)*5.0/9.0;}}
};
also does not work as that is error: invalid use of ‘auto apparently. I am not sure how else to write this, as apparently lambdas do not have a defined type
std::function<double, double>in your case. Use that as type in your map.std::function<>. This will work in every single case, and perhaps irrelevant to this question, but this same thing works in C# (only it'sAction<>orFunc<>) and I use it at least a couple of times in every project.std::functionI am afraid.std::map<std::string, std::function<double(double)>>. godbolt.org/z/644Phj