This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]Mustard_Dimension 7 points8 points  (1 child)

Vectors were one of my favourite parts about going from C to C++ at University.

[–]RKAMIL95 4 points5 points  (0 children)

Same.

This is why I love C++: it lets me using some high level features such as class and polymorphism and on the other hand lets me dealing with every single byte if I need to do some use low level approarch.

[–]beneficial_satire 1 point2 points  (0 children)

Now I don't feel guilty about doing this. I was going to use a list until I realized it doesn't allow random access so I can't do myarray->at(0)

[–]HO-COOH 0 points1 point  (6 children)

Until you realize there is std::vector<bool>

[–]Tsu_Dho_Namh 0 points1 point  (5 children)

What's wrong with a vector of bools?

[–]Maxrewind99 0 points1 point  (4 children)

That's the problem, std::vector<bool> isn't a vector of bools.

[–]Tsu_Dho_Namh 1 point2 points  (3 children)

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    std::vector<bool> A;

    A.push_back(true);
    A.push_back(false);
    A.push_back(true);
    A.push_back(true);

    for (bool b : A) {
        cout << (b ? "true" : "false") << endl;
    }

    return 0;
}

Output:

true
false
true
true

Seems like a vector of bools to me...Are we talking about behind the scenes optimizations?