move

How do you properly implement gravity to a free floating space object and some sort of friction when thrusting in opposite direction

房东的猫 提交于 2021-02-02 03:44:50
问题 I am trying to program movement that is basically like Asteroids where once UP button is pressed you accelerate to a certain speed and then because in space you don't stop and can only slow down by thrusting in opposite direction. On top of that, I would like gravity to be pulling you towards the bottom of the screen. I have this accomplished for the most part but the issue I have is: When I turn around and thrust opposite direction, it doesn't slow down first going backwards before starting

Method for safely moving all elements out of a generic array into a tuple with minimal overhead

旧巷老猫 提交于 2021-01-27 17:30:04
问题 In Rust, I want to move all the elements out of a generic fixed-width array so I may then move them individually. The elements may but don't necessarily implement Copy . I've come up with the following solution: struct Vec3<T> { underlying_array: [T; 3] } impl<T> Vec3<T> { fn into_tuple(self) -> (T, T, T) { let result = ( unsafe { mem::transmute_copy(&self.underlying_array[0]) }, unsafe { mem::transmute_copy(&self.underlying_array[1]) }, unsafe { mem::transmute_copy(&self.underlying_array[2])

Is it possible to define a 'move-and-swap idiom' equivalent in C++03

不想你离开。 提交于 2021-01-27 16:10:17
问题 I'm bound to C++03 and I have a non-copyable object (e.g. holding a resource). I need to use move-and-swap semantics to be able to do something similar and avoid copies: MyClass returnMyClass(void) { MyClass temp; // fill 'temp' members with actual data return temp; } int main(void) { MyClass test; test = returnMyClass(); // need to avoid copies } Is it possible to respect all these requirements in C++03? It is basically the same case of this, but for C++03. To put the question in other words

map/unordered_map with non-movable, default constructible value type

三世轮回 提交于 2021-01-27 11:28:46
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

map/unordered_map with non-movable, default constructible value type

点点圈 提交于 2021-01-27 11:27:50
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

map/unordered_map with non-movable, default constructible value type

此生再无相见时 提交于 2021-01-27 11:27:01
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

map/unordered_map with non-movable, default constructible value type

蹲街弑〆低调 提交于 2021-01-27 11:23:26
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

Access elements of vector<std::unique_ptr<T> > using an iterator?

六月ゝ 毕业季﹏ 提交于 2021-01-24 08:13:03
问题 I have a class member variable as vector<std::unique_ptr<T> > v; and a member function where I want to use a unique_ptr element of v "addressed" by an iterator argument. Which one is better? void mem_fun(vector<std::unique_ptr<T> >::iterator it) { std::unique_ptr<T> p; p = std::move(*it); ... } Or void mem_fun(vector<std::unique_ptr<T> >::iterator it) { std::unique_ptr<T>& p = *it; ... } From what I know, it seems the second way just kind of violates the "uniqueness" of unique_ptr . But can

Access elements of vector<std::unique_ptr<T> > using an iterator?

元气小坏坏 提交于 2021-01-24 08:04:57
问题 I have a class member variable as vector<std::unique_ptr<T> > v; and a member function where I want to use a unique_ptr element of v "addressed" by an iterator argument. Which one is better? void mem_fun(vector<std::unique_ptr<T> >::iterator it) { std::unique_ptr<T> p; p = std::move(*it); ... } Or void mem_fun(vector<std::unique_ptr<T> >::iterator it) { std::unique_ptr<T>& p = *it; ... } From what I know, it seems the second way just kind of violates the "uniqueness" of unique_ptr . But can

Access elements of vector<std::unique_ptr<T> > using an iterator?

荒凉一梦 提交于 2021-01-24 08:04:05
问题 I have a class member variable as vector<std::unique_ptr<T> > v; and a member function where I want to use a unique_ptr element of v "addressed" by an iterator argument. Which one is better? void mem_fun(vector<std::unique_ptr<T> >::iterator it) { std::unique_ptr<T> p; p = std::move(*it); ... } Or void mem_fun(vector<std::unique_ptr<T> >::iterator it) { std::unique_ptr<T>& p = *it; ... } From what I know, it seems the second way just kind of violates the "uniqueness" of unique_ptr . But can