Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4258092
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:36:11+00:00 2026-05-21T05:36:11+00:00

I posted the following code on rosettacode.org for the task of converting Arabic and

  • 0

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 used to work just fine, but now I get a compiler error.

Error: template
std.algorithm.indexOf(alias pred = “a
== b”,R1,R2) if (is(typeof(startsWith!(pred)(haystack,needl
e)))) does not match any function
template declaration

According to the documentation indexOf is deprecated, and countUntil should be used in stead, but it gives me the same error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:36:11+00:00Added an answer on May 21, 2026 at 5:36 am

    Long story but I’ll try to keep it short:

    std.algorithm.indexOf expects an input range, which is a structural type that must define front, popFront() and empty. For arrays, these methods are defined in std.array and work via uniform function call syntax, which allows fun(someArray) to work the same as someArray.fun().

    immutable string[] is not an input range, since popFront removes the first element of the array, which cannot be done for an immutable type. The fact that this used to work was a bug.

    I’ve updated the Rosetta Code entry to change symbols to an immutable(string)[]. Here, the elements of symbols are immutable, but the array may be sliced and reassigned. For example:

    void main() {
        immutable string[] s1 = ["a", "b", "c"];
        immutable(string)[] s2 = ["d", "e", "f"];
    
        s2 = s2[1..$];  // This is what std.array.popFront does under the hood.
        assert(s2 == ["e", "f"]);  // Passes.
        s2[1] = "g";     // Error:  Can't modify immutable data.
    
        s1 = s1[1..$];  // Error:  Can't modify immutable data.
        s1[1] = "g";    // Error:  Can't modify immutable data.
    }
    

    immutable string[] is implicitly convertible to immutable(string)[] but implicit function template instantiation (often denoted IFTI; this is what’s used to instantiate the indexOf template) is not smart enough try this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in a layout: Posted <%=time_ago_in_words post.created_at %> ago <%
The following is based on the code that I posted on this thread .
i am trying to search in amazon product database with the following code posted
The following code renders differently in IE7 and FF3 (NEW CODE POSTED OLD CODE
The following code has segfault problems (It is also posted at pastebin ): #include
I have the following code: <video width=640 height=360 controls id=video-player poster=/movies/poster.png> <source src=/movies/640x360.m4v type='video/mp4;
Following a question posted here about how I can increase the speed on one
Following on from a question I posted yesterday about GUIs, I have another problem
When the following code is run on the iPhone (ios 3.1) the count of
Consider the following code: Dim Working As Boolean = False Private Sub TreeView1_AfterCheck(ByVal sender

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.