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

The Archive Base Latest Questions

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

This has stumped me for a few hours now, since I cannot see any

  • 0

This has stumped me for a few hours now, since I cannot see any problem in the math or code. (Dispite staring at it and working it out over and over again to be sure.) I’m hoping you folks can help me, here’s my code:

#define SOLVE_POSITION(x, y, z) ( z*16  +  y*4  +  x )

std::bitset<64> block;
block.reset();

for(int z = 0; z < 4; ++z){
    for(int y = 0; y < 4; ++y){
        for(int x = 0; x < 4; ++x){

            if(block.at(SOLVE_POSITION(3-x, y, 3-z))){  //<-- call to at() throws 'out_of_range'

                // do stuff
            };
        };
    };
};

With z being 0, the two inner most for loops run their course entirely (for a total of 16 passes.) However, once z becomes 1, that’s when the exception is thrown from within std::bitset<64>::at().

The values of z, y, x are respectively 1, 0, 0 at that moment.

Can you tell me what is happening here to cause this exception?
Thanks in advance!

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

    Macros! You have to be really careful about this:

    You define:

    #define SOLVE_POSITION(x, y, z) ( z*16  +  y*4  +  x )
    

    so when you do:

    SOLVE_POSITION(3-x, y, 3-z)
    

    it expands to:

    ( 3-x*16 + y*4 + 3-z )
    

    and because of operator precedence, 3-x*16 will be incorrect! You need to do:

    #define SOLVE_POSITION(x, y, z) ( (z)*16  +  (y)*4  +  (x) )
    

    so that it expands correctly to:

    ( (3-x)*16 + (y)*4 + (3-z) )
    

    as expected.

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

Sidebar

Related Questions

This problem has got me stumped for a few days now. I have a
Been using git for a few months now and this one has me stumped.
Finding a good way to do this has stumped me for a while now:
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({
This one has me stumped. Here are the relative bits of code: public AgencyDetails(Guid
I'm not sure why this has stumped me. I have the following code $website
I'm new to WPF and this following has stumped me for a while now:
This has stumped me for some time. My problem: I have 2 different tables..
This really has my stumped today. I'm sure its simple, but... Here is my
This one has me stumped. I've got a java.sql.ResultSet and I'm pulling string values

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.