I posted the following code on rosettacode.org for the task of converting Arabic and Roman numerals .
import std.regex, std.array, std.algorithm; immutable { int[] weights = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; string[] symbols = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]; } string toRoman(int n) { auto app = appender!string; foreach (i, w; weights) { while (n >= w) { app.put(symbols[i]); n -= w; } if (n == 0) break; } return app.data; } int toArabic(string s) { int arabic; foreach (m; match(s, "CM|CD|XC|XL|IX|IV|[MDCLXVI]")) { arabic += weights[symbols.indexOf(m.hit)]; } return arabic; }
It worked fine, but now I get a compiler error.
Error: std.algorithm.indexOf pattern (alias pred = "a == b", R1, R2) if (is (typeof (startsWith! (Pred) (haystack, needl e)))) does not match any function announcement template
According to the documentation, indexOf is deprecated and countUntil should be used instead, but it gives me the same error.
fwend
source share