How do I use a boolean vector with if-else?

Let me explain exactly what I mean.

I've got a recursive function that works with roughly the following pseudocode

int funct (vectorlist1, param2, ..., vector<bool> values)
if (a > b)
call recursive function for the next value in vectorlist1
else
values.at(i) = true
call recursive function for next values in vectorlist1

My issue is that the boolean vector I'm using (initially set to the default false value) gets entirely set as true, but I only want the value that gets used in else from vectorlist1 to set the boolean vector's corresponding index to true. Meaning: vector1.at(i) = used value, then boolvector.at(i) = true.
How do I do that, how do I assign only the index I need with true, instead of the whole boolean vector?
Last edited on
.at is notably slower than [i] notation because it checks i to be valid. Only use .at() if you are unsure that i is correct (and I advise getting i correct instead of using at even then).

.at or [] either one only sets ONE location to true.
you must have a logic error -- remember that recursion is almost always either a substitute for a loop or a loop with a stack data structure. Its likely that your recursive calls are setting various elements to true at different invocations; its not setting it all at once.
if you posted the code and told us what its supposed to do, it would be easier to help from here...

(to see this, try doing what you did in main on a test vector of bool, without the recursion, and watch it only set one value there).
Last edited on
Topic archived. No new replies allowed.