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 7576819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:00:55+00:00 2026-05-30T17:00:55+00:00

Real opIndex(size_t row, size_t col = 0) const pure nothrow { assert(col + row

  • 0
Real opIndex(size_t row, size_t col = 0) const pure nothrow {
  assert(col + row * Col < Row * Col, "index out of bounds.");
  return _data[col + row * Col];
}

Today this assertion failed, and I wanted to see the actual values of row and col. Unfortunetly, assert isn’t like writeln or writefln, so I can’t do something like:

assert(col + row * Col < Row * Col, "index out of bounds. row: %d  col: %d", row, col);

I even tried this:

assert(col + row * Col < Row * Col, "index out of bounds" ~ to!string(row)~ " " ~ to!string(col));

But I can’t call to because opIndex is pure. I could temporarily remove pure from opIndex, but that triggers a long chain of undos because other pure methods are calling opIndex. Not being able to call to also eliminates the possibility of creating my own function to pass to assert.

So, What else is there to try? I just want to print such values when assertion fails.

  • 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-30T17:00:57+00:00Added an answer on May 30, 2026 at 5:00 pm

    For the moment, if you want to convert to or from strings in a pure function, you’re going to have to write the conversion functions yourself. Some work has gone into making functions like std.conv.to pure, but we haven’t yet reached the point where they are. Too many lower level constructs still aren’t pure, even if they theoretically could be. A lot of work is being put into making stuff const-correct for the next release of dmd (2.059), and some work on pure goes hand-in-hand with that, since certain functions in Object are going to have to be pure, const, @safe, and nothrow. So, there’s a good chance that std.conv.to will be able to be pure for converting to and from strings with the next release. And even if it doesn’t happen with the next release, it’s going to happen soon, since it does need to happen (as your predicament illustrates). But until then, you’re on your own.

    Assuming that all of that was sorted out, then the best way to create a string for your assertion would be

    assert(col + row * col < row * col,
           format("index out of bounds. row: %d  col: %d", row, col));
    

    which will work in a impure function, but until format can be pure, it won’t work in a pure one.

    Now, you can put impure stuff in a debug block. So, if you wanted to, you could do

    debug
    {
        assert(col + row * col < row * col,
               format("index out of bounds. row: %d  col: %d", row, col));
    }
    

    but then you’d have to compile with -debug or your assertion wouldn’t be run. But regardless, debug will allow you to put impure code in your your pure function for debugging purposes and will be compiled in as long as the -debug flag is used, so it can serve as a temporary workaround for the current deficiencies of format and to.

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

Sidebar

Related Questions

The real question is this: I am trying to figure out the effect of
Real UID, effective UID, and some systems even have a saved UID. What's the
REAL newbie here to Objective C and Cocoa. I have this 'if statement' if
Real problem with an existing webapp which has been working for the last couple
What real-world projects would you suggest looking through the sources? As I'm learning Java
What real (i.e. practical) difference exists between a static class and a singleton pattern?
Our real estate website sends email notifications when properties come on the market matching
In real mode segmented memory model, a segment always begins on a paragraph boundary.
The real question: Is there a way to clear certain attributes for all components
A real F# noob question, but what is |> called and what does it

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.