Dima
Didn’t see lol
Daniele
For example classname::destroy() { vector.erase(); }
Daniele
Use ref?
what do you mean?
Dima
Check out quake 3 source code
Vlad
That will be called automaticaly
Anonymous
Bruh
Daniele
Let me explain better: I have a method (Ship::destroy()) that will be called from different functions and needs to esare an element of a vector when called. I thought of doing something like void Ship::destroy(std::vector<Ship>& vector, int index) { vector.erase(index); } but is there a way to do it without having to pass both the vector and the index to the function?
Daniele
since this is a method call
Vlad
template<typename Container, typename Functor> void remove(Container&& c, Functor&& f) { c.erase(std::remove_if(std::begin(c), std::end(c), f), std::end(c)); } .... std::vector<int> vec(20, 0); remove(vec, [](auto& a){ return a % 2;});
Vlad
This would do for a general removal
Vlad
Where you would store vector of those ships
Kenny
Do you have a vector un your private part?
Daniele
so the ship is a vector because there could be more of them (it's not the level, is a character), everytime I call the destroy method I want that element to be removed from the vector and disappear. the vector is declared in the main, but each element is deleted individually from a class method, not from the main
Daniele
Looks like your architecture is a bit of a mess :P
what could be a better way to make characters?
Daniele
I need to create and remove them dynamically
Vlad
what could be a better way to make characters?
I'll give you the link to my repo in dm. Have a look.
Daniele
ok
Ибраги́м
Hey plebes
Ибраги́м
https://github.com/eliaskosunen/scnlib
Vlad
Hey plebes
>plebes Hey buddy, I think you've got the wrong door, the leather club's two blocks down.
amninder
Can anyone please explain me what >>= mean in b >>=1
amninder
Actually im trying to understand binary exponantation
amninder
Thanks
amninder
Same as b /= 2
If we can do like this b / = 2 Why there is b >>=1 In language
amninder
Just wonder
Vlad
Also without optimization /= 2 could be an actual division instead of faster bit shifting
amninder
Okay
amninder
amninder
They are quite fast.
Okay thanks for the info man
Vlad
On modern architectures could be done concurrently with other instructions with almost zero cost.
Shaquil
Thank you
Dima
@roxifas ( ͡° ͜ʖ ͡°)
RV
Asdew
None of those. Real practice is the best.
RV
We need any one of the platforms to practice right.
Asdew
No.
Asdew
Just write real programs. That's the practice you need.
Asdew
You'll never get good at real C programming if all you do is small, easy practice questions.
RV
How to crack interview questions then
Asdew
Don't worry about interviews, worry about how you actually program.
RV
Thanks bud 👍
Anonymous
#cpp #quiz #advanced C++20 quiz
Anonymous
struct N { constexpr N() {} N(N const&) = delete; }; template <typename T> consteval void assert_copyable() { T t; T t2 = t; } using check = decltype(assert_copyable<N>());
Daniele
can std::vector erase() delete the last element of a vector?
Asdew
Ill-formed just because it's ugly and hard to understand.
Dima
+
+++++++++
Anonymous
can std::vector erase() delete the last element of a vector?
cppreference.com Checkout the docs before asking a question
Dima
Roxifλsz 🇱🇹
It's too boring
If you're looking for """"fun"""" in code, sure, but I just want my code to work and also not be an unreadable plate of spaghetti
Daniele
I will change my question in: i there a reason why a std::vector erase() would work with one class and not the other?
Roxifλsz 🇱🇹
*javascript and python are looking thru the dark room*
Shut up, do not remind me of those cursed hellscapes
Daniele
I have one vector made of 1 item and another vector made of 20 items, vector.erase(vector.begin() + index) works fine on the vector made of 20 items but not on the vector made of 1 item
Daniele
Anonymous
Show the Ship class definition
Daniele
Daniele
this works, the other doesn't
Anonymous
And Asteroid one