Josh Posted January 10, 2017 Share Posted January 10, 2017 Is there any way to set an iterator to a state or value that marks it as "invalid"? I end up storing a boolean member along with every iterator like "addedtoshadowcasterupdatelist". It would be a lot easier if I could set set iterator=0 when it is initialized or removed from a list. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
martyj Posted January 10, 2017 Share Posted January 10, 2017 It would be a lot easier if I could set set iterator=0 when it is initialized or removed from a list. Are you referring to setting the iterators value = NULL? Maybe something like this? std::vector<Entity*> entities; for(auto it = entities.begin(); it != entities.end(); it++) { if(condition) { *it = NULL; } } Idk if that would work, iterators are just pointers to each element. I'm not too proficient at my C++, more of a C, just a guess. Quote Link to comment Share on other sites More sharing options...
f13rce Posted January 10, 2017 Share Posted January 10, 2017 He's referring to the iterator, not iterator value. But you can you use the value of the iterator as a flag, although it can be dangerous in case an object or variable does have that value. An alternative way could perhaps be using it = list.end(), as end() has no value assigned to it. I don't really think there's a clean way to set it to "invalid" in any other way. Quote Using Leadwerks Professional Edition (Beta), mainly using C++. Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz Previously known as Evayr. Link to comment Share on other sites More sharing options...
Josh Posted January 10, 2017 Author Share Posted January 10, 2017 The problem with the list.end() method is you need a list to compare it to. Okay, create a global one. Now you need one for every single type of list that might exist! I have never set the value of an iterator like that. Is that safe and portable? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
f13rce Posted January 10, 2017 Share Posted January 10, 2017 I've never tried it myself, so use it at your own risk I suppose... Quote Using Leadwerks Professional Edition (Beta), mainly using C++. Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz Previously known as Evayr. Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2017 Share Posted January 10, 2017 t would be a lot easier if I could set set iterator=0 when it is initialized or removed from a list. You're storing iterators in a list? What's the goal with this request? Why do you want to do that when it's initialized or removed from a list (still seems odd to store iterators in a list)? Quote Link to comment Share on other sites More sharing options...
Josh Posted January 10, 2017 Author Share Posted January 10, 2017 No, I store list iterators for fast removal. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.