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

  • Home
  • SEARCH
  • 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 9001153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:23:55+00:00 2026-06-16T00:23:55+00:00

I have a 2d rectangular grid and I need to apply different functions to

  • 0

I have a 2d rectangular grid and I need to apply different functions to a subset of nodes in this grid. The subset is given by rectangular bounds e.g. row and column delimiters. Since I do not want to code the iteration with 2 for loops over and over again I am considering two approaches to solve this problem:

First create a custom iterator provider which is initialized using the rectangle limits and then keeps them while he is iterated. While this is feasible it seems quite some work to make this iterator compliant e.g. with standard stl aglorithms.

The second approach is to pass a function pointer into the function the traverses both for loops and execute it in the inner loop. This is feasible as well but might create quite ugly syntax since i have to pass member functions.

Which way is usually preferable ? And are there any clean examples for such a use case, to keep me from reinventing the wheel ?

Note: The operation is quite performance critical since the code is frequently executed

  • 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-06-16T00:23:56+00:00Added an answer on June 16, 2026 at 12:23 am

    From design point of view I would say iterator approach is better, because it places less complexity on loop body (and likely there will be more complexity than in the iteration).

    But I would expect better performance with functor approach. Especially if you will make it in STL-style (template parameter with expected operator() ).

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

Sidebar

Related Questions

In this earlier question the OP asked the following problem: Given a rectangular grid
I have a grid of rectangular cells covering a plane sitting at some distance
I have a set of numbers which I need to put on a rectangular
I have the bounds of a rectangular box. Is it possible to fit a
I have a rectangular map, stored as multidimensional array (ie $map[row][col] ) and I
I have a fluid grid (in height and width). The LIs are always rectangular
Help needed.. I have a organization layout which have rectangular shapes not in an
I have N rectangular items with an aspect ratio Aitem (X:Y). I have a
I have the following rectangular image to be set in my application. Now I
I have divided a rectangular shaped image into two pieces as as shown below

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.