MBZ
MBZ

Reputation: 27582

Iterate shared_ptr<std::vector<T>>

Let's assume I have the following:

auto vec = std::shared_ptr<std::vector<T>>

And I want to loop through all the vec entities using C++11 Range-Based for Loop.

The following works:

for (auto entity: *vec)

my question is there anyway to do the same without using the * operator?

Upvotes: 5

Views: 2638

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254431

No. The only sensible way to dereference a pointer is with the dereference operator.

Upvotes: 15

Related Questions