473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Generalized Loops

Its been a while since I've programmed in C++ but I need to write a small
program.

The idea is that I need to do several nested for loops.

Since I don't think I can easily handle doing the loops directly, except
maybe through recursion but at a cost, I was thinking I could use templates
to generate the code. The problem is that I have completely forgot just
about everything I learned about templates.

What I want to do is have a template that will basicaly generate a nested
set of N for loops and supply me with an array like structure to access the
ith for loops current value.

Basicaly I need to do the code

for(i1 = 0; i1<= m; i1++)
for(i2 = 0; i2<= m; i2++)
.............
for(in = 0; in<= m; in++)
{
x = F[k]; // return's ik's current value...
// i.e., if k = 4, then x = i4
// code here
}

Technically I can't have ik = 1 but i think I could handle figuring that
out.

I work on trying to figure it out but right no my brain is fried and I'd
like to know if this is even possible before I try.

Thanks,
Jon
May 29 '06 #1
1 1621
* Abstract Dissonance:
Its been a while since I've programmed in C++ but I need to write a small
program.

The idea is that I need to do several nested for loops.

Since I don't think I can easily handle doing the loops directly, except
maybe through recursion but at a cost, I was thinking I could use templates
to generate the code. The problem is that I have completely forgot just
about everything I learned about templates.

What I want to do is have a template that will basicaly generate a nested
set of N for loops and supply me with an array like structure to access the
ith for loops current value.

Basicaly I need to do the code

for(i1 = 0; i1<= m; i1++)
for(i2 = 0; i2<= m; i2++)
.............
for(in = 0; in<= m; in++)
{
x = F[k]; // return's ik's current value...
// i.e., if k = 4, then x = i4
// code here
}

Technically I can't have ik = 1 but i think I could handle figuring that
out.

I work on trying to figure it out but right no my brain is fried and I'd
like to know if this is even possible before I try.


You don't need a template.

Use a vector of n numbers; define a function to increment the vector in
the same way you'd increment a base m+1 number.

But first, think about whether you really want your loop body executed
(m+1)^(n+1) times: plug in a few typical values for m and n in your
calculator.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: venkat | last post by:
Hi, I want to solve linear least sqaure problem( min||c-Ax||2 subject to Bx=d ). How do I do it in python. lapack has a routine for doing this (DGGLSE). Can I access this from python? TIA,...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
5
by: squidco | last post by:
I've been trying to wean myself off of tables. I've been reading about the float property, and have implemented a couple of sites using divs instead of tables, and generally I'm happy with the...
6
by: christopher diggins | last post by:
I wrote a dynamic matrix class similar to the one described in TCPL 3rd Edition. Rather than define two separate iterators for const and non-const scenarios I decided to be a lazy bastard and only...
5
by: Jean-Guillaume Pyraksos | last post by:
I want to work with "generalized lists" as in Lisp, say : ((23 () . 2) () ((10))) ; only pointers and integers So the basic element is a node, a struct with two fields car and cdr....
10
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise...
3
by: Spectre1337 | last post by:
Hello, I've encountered a rather puzzling problem with SqlDataAdapter. I've set up a number of elaborate tables in the Microsoft SQL Server Management Studio Express (including several table key...
3
by: | last post by:
I am enjoying making generalized methods to serve common needs, such as: ImageProcessing.MakeQuickResize(); ImageProcessing.Sharpen(); FileOps.CreateYearAndMonthAndDayDirectoryBasedOnDate()...
5
by: er | last post by:
hi, is anyone aware of a library that generalizes transform, for_each? e.g. transform( vec1.begin(), vec1.end(), vec2.begin(), vec3.begin(),
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.