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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:30:52+00:00 2026-05-23T19:30:52+00:00

wikipedia ( here ) gives a compile time unrolling of for loop……. i was

  • 0

wikipedia (here) gives a compile time unrolling of for loop…….
i was wondering can we use a similar for loop with template statements inside…
for example…

is the following loop valid

template<int max_subdomain>
void Device<max_sudomain>::createSubDomains()
{
    for(int i=0; i< max_subdomain; ++i)
    {
        SubDomain<i> tmp(member);
        ...
        // some operations on tmp
        ...
    }
}

SubDomain is a class which takes in the a template parameter int and here has been constructed with an argument that is a member of the Device class.

Thanks for the answer guys…
now that you know what i want…
is there anyway i achieve what i want to??

i finally got what i wanted…………..
instead of using the for loop directly…
one can instead use the Boost::MPL for_each construct. I haven’t yet implemented it but I am guessing that this provides a way to do what i wanted…..

I took the answer from another stack overflow question here… However the comment to the same question decries its use because it would be very slow (for large for loops of course)… however.. for loops which are not large i don’t think there should be any bloating… i’ll try the code and let you know the results….

the use is illustrated well in the example

  • 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-23T19:30:53+00:00Added an answer on May 23, 2026 at 7:30 pm

    Re-Edit:

    My previous answer was correct. I have tried your code, it’s giving compiler error. You cannot declare objects like that, as i cannot remain a compile time constant (as you are intending to do i++). template parameter must always be compile time constants. Here is the demo.

    Also note that, loop unrolling is done for normal loops also, as part of optimization by compilers. It’s not limited to templates.

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

Sidebar

Related Questions

here's a definition of marshaling from Wikipedia: In computer science, marshalling (similar to serialization)
The singleton is explained here: http://en.wikipedia.org/wiki/Singleton_pattern#PHP_5 . I want to use the singleton class
I found a perl script that manages randomizing the wikipedia articles in Wikipedia here
Here is the wiki for those who want to know about Apache CXF. http://en.wikipedia.org/wiki/Apache_CXF
I've been reading about thread-safe singleton patterns here: http://en.wikipedia.org/wiki/Singleton_pattern#C.2B.2B_.28using_pthreads.29 And it says at the
I've been reading about web services here on SO, on Wikipedia, Google, etc., and
where can I get some statistics about platform version and resolution as given here
Wikipedia says on A* complexity the following ( link here ): More problematic than
My team is coding an application that involves editing wikipedia-like pages. It is similar
I have search in google. I found something here, http://paulbourke.net/dataformats/bmp/ , but i can't

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.