FAQ Database Discussion Community


Replace class new[] variables with vectors - move, copy operators

c++,c++11,vector,move
I made a sparse matrix class for some work I am doing. For the sparse structures, I used pointers, e.g. int* rowInd = new int[numNonZero]. For the class I wrote copy and move assignment operators and all works fine. Reading about the move and copy semantics online, I have tangentially...

Std::stringstream move assignment not working in gcc

c++,move,stringstream,move-assignment-operator
An assignment like the following std::stringstream strstr; strstr = std::stringstream(someString) does give me an error when compiling in gcc: error: use of deleted function ‘std::basic_stringstream<char>& std::basic_stringstream<char>::operator=(const std::basic_stringstream<char>&)’ Now, I know that streams apparently cannot be copied and the copy constructor of std::stringstream is marked as deleted. However, to my understanding...

How to make smoth elements dragging by mouse if their position set in percents?

javascript,html,mouse,move,elements
I doing elements dragging possibility in my page. User should drag any element with % or px set position. The dragging of px positioned elements works good, but the dragging of % positioned elements is too fast and element runs away from mouse. Which way I can fix this? I...

javafx using translatetransition and keyevent to move image around screen

javafx,transition,move,translate,keyevent
I am trying to make a simple tile based movement system so that when a direction is pressed a translate transition is played to smoothly move the character one tile over. The problem I am running into is that when I play the animation the image does the transition fine...

Which rules determine whether an object is trivially copyable

c++,c++11,move
With the introduction of c++11, trivially copyableness has gotten quite relevant. Most notably in the use of 'std::atomic'. The basics are quite simple. A class foo is trivially copyable if: foo* src = new foo(); foo* dest = malloc(sizeof(foo)); memcpy(dest, src, sizeof(foo)); Has the same effect as: foo* src =...

HOw to move my bullet slowly in java?

java,move
Hi I am developing a game that a fighter moves right and left and shoots. For the shooting part, I tried to use a for loop to slow the speed down and user can see the bullet. But it wasn't enough. I used sleep too but not a good answer....

R-value Reference push_back Function

c++11,move,encapsulation,rvalue-reference,push-back
I'm writing a Queue class. I have two versions of push_back for the new C++11 standard. One of these versions uses a rvalue reference as a parameter. My version works, but I think it must be lacking something: 97 template <typename T> 98 void Queue<T>::push( T && val ) 99...

How to move a file to another directory and write its filename to a file (create and append) within a loop in C# for SSIS Script Task?

c#,file,foreach,ssis,move
Below is the code that loops all the *.tar.gz files in the source directory. Each file is compared to both variables dayOld_7 and dayOld_14. If equal then set the dayOld_7 flag or the dayOld_14 flag to True. If the file is not one of them, the file has to be...

How to move folder/files with path names > 255 characters in Windows 8.1?

file,copy,windows-8.1,folder,move
I have looked around for ages, and the only possible way I have found is to use the subst method. I don't want to mess about with this. I simply want to copy/move a directory, X, to location Y. How can you copy/move a folder or file with path name...

Python Tkinter - Toplevel MoveInAnimation

python,animation,tkinter,move,toplevel
Is there an option to simply move a Tkinter TopLevel() window on runtime by using an animation? I thought about a smooth moveInAnimation triggered by a button. Here is some code snippet: from Tkinter import Toplevel class MoveInTopLevel(Toplevel): ''' Animated MoveInToplevel. ''' def __init__(self, *args, **kwargs): Toplevel.__init__(self, *args, **kwargs)...

C++ 11 - Is moving non local variable safe? [duplicate]

c++,c++11,stl,move
This question already has an answer here: Does moving leave the object in a usable state? 2 answers Say I have a function which goes like: void a_fct( std::vector<double> &some_vector ) { std::vector<double> a_temporary_vector = some_vector; ... some stuff involving only a_temporary_vector ... some_vector = a_temporary_vector; } which is...

C++ disallow cast to rvalue reference

c++,c++11,move
As always with variables which have been std::move'd, it is unsafe to use them afterwards. As I have written a code where I encourage the user to apply std::move on various occasions, I want to avoid that it is used in a wrong way, at least in a few crucial...

Why Can't I move an Element of a map?

c++,dictionary,key,const,move
I want to be able to change the key of an element of a map. I thought that a good way to handle that would be to move the element from the map, as follows: map<char, int> foo{{'a', 1}, {'b', 2}, {'c', 3}}; foo['z'] = move(*foo.find('c')).second; for(auto& i: foo){ cout...

Shell Script to move photos into folders with date YYYYMMDD

shell,date,move,folders,bulk
I have an IP cam that sends a photo every minute to a folder on a PC (Linux) with (mv *20150501* 20150501). Where the camera sends following filename: Schedule_20150501-103642.jpg I would like to make a shell script that: Lookup in the file name for date in format YYYYMMDD and if...

sprite is not moving down

python,pygame,sprite,move
I do not know how to create new sprites by mouse click and add a movement to all new sprites. I have created a simple game: Diamond : move left/right with K_LEFT, K_RIGHT Pad: move left/right with mouse if you click a mouse you append hearts and draw a sprite...

Logger logs 2 times instead of one time because of copy

c++,logging,copy,move
I am writing my own Logger. I know there are alot out there but i would like to write it myself. It has messages which get logged when they are leaving the scope. So if i call Logger::Error(__FILE__,__LINE__) << "some error" it gets logged directly since there is no assignemnt...

std::move to a function

c++,std,move
I have this example code: #include <iostream> class Struct { public: Struct() { std::cout << "0" << std::endl; } Struct(Struct&) { std::cout <<"1"<<std::endl;} Struct(const Struct&) { std::cout << "2" << std::endl; } }; class Struct2 { public: Struct s; Struct2() {} void setMember(const Struct& aux) { s = aux; }...

Does deleting a copy constructor or copy assignment operator count as “user declared”?

c++11,move,language-lawyer,copy-constructor
Per this presentation, if either the copy constructor or copy assignment operator is "user declared", then no implicit move operations will be generated. Does deleteing the copy constructor or copy assignment operator count as "user declared"? struct NoCopy { NoCopy(NoCopy&) = delete; NoCopy& operator=(const NoCopy&) = delete; }; Will implicit...

Is value returned by std::unique_ptr::get valid after moving unique_ptr?

c++11,move,unique-ptr
Consider the following code snippet: class Owner { public: Owner(std::unique_ptr<int> ptr) : owned_pointer<int>(std:move(ptr)) {} private: std::unique_ptr<int> owned_pointer; }; std::unique_ptr<int> ptr(new int); int* ptr1 = ptr.get(); Owner new_owner(std::move(ptr)); Is it safe to assume that ptr1 is valid as long as new_owner stays in scope? It seems to work, but I can't...

copy list initialization vs direct list initialization of temporary

c++11,move,temporary-objects,list-initialization
Given the following struct: struct ABC { ABC(){cout << "ABC" << endl;} ~ABC() noexcept {cout << "~ABC" << endl;} ABC(ABC const&) {cout << "copy" << endl;} ABC(ABC&&) noexcept {cout << "move" << endl;} ABC& operator=(ABC const&){cout << "copy=" << endl;} ABC& operator=(ABC&&) noexcept {cout << "move=" << endl;} }; The...

excel vba move each text file to a new directory using the file name?

excel,vba,excel-vba,move
i am using the following vba code to import all my text files onto a new row in excel. This bit works fine, the next thing I want to do is once this has imported the text files, I want each text file to be moved from one directory 'Z:\NS\Unactioned\'...

Java move application to startup folder

java,move,startup,autostart
I am trying to add my APP to startup folder. public class info { public static String getautostart() { return System.getProperty("java.io.tmpdir").replace("Local\\Temp\\", "Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup"); } public static String gettemp() { String property = "java.io.tmpdir"; String tempDir = System.getProperty(property); return tempDir; } public static String getrunningdir() { String runningdir = ProjectGav.class.getProtectionDomain().getCodeSource().getLocation().getPath(); return...

std::move on a C++ class does not move all members?

c++,c++11,move
I understand that using v.push_back(std::move(foo)) will move foo contents to a vector. However I do not understand why the below code : #include <iostream> #include <vector> struct Foo { std::string s; float f; friend std::ostream& operator<<(std::ostream& stream,const Foo& foo) { stream << "{" << foo.s << ":" << foo.f <<...

How to move a struct with promise inside it?

c++,copy,promise,move
Recently I have read a part of "Concurrency in action" book concerning parallel quicksort implementation. I tried to check the code mentioned in the book and received an error on this part: struct listPart { list<T> data; promise<list<T>> promise; }; listPart newLowerPart; ... parts.push(move(newLowerPart)); The compiler gives the error std::promise::promise(const...

Using Batch file to search for a file containing an input then moving it to another directory

batch-file,find,move
@echo OFF @find /c /i "james" "C:\Users\ersojt\Desktop\Sample\*.eml" > NUL if %ERRORLEVEL% EQU 0 ( move "C:\Users\ersojt\Desktop\Sample\*.eml" "C:\Users\ersojt\Desktop\Sample2" ) else ( @echo Failure ) PAUSE I am trying to use a Batch file to search for a specific file containing an input; then moving this file to another directory. Can anyone...

How to move undecorated JFrame by holding click on a JPanel in Java? [duplicate]

java,swing,jframe,jpanel,move
This question already has an answer here: Drag and Resize undecorated JFrame 1 answer I've been making an undecorated JFrame so far and I was wondering if it's possible to move the undecorated JFrame by holding click on a JPanel. Here is the source code I'm working on. private...

C++ unordered_map move beginner error

c++11,move,unordered-map
Sorry for the noob question here, but i don't even know what to search on google. I tried some documention on the move semantic but i still can't solve my problem. So if somebody can give me some clues, i'll be really thanksfull. About the code: graph.hpp: #ifndef GRAPH_HPP #define...

Move files from multiple folders to multiple folders in Linux

bash,file,move,folders
How can I move files from multiple folders to another location. For example if I have 3 folders with name /test/folder1, /test/folder2, /test/folder3 and I want to move the contents of these folders into another location like /temp/folder1, /temp/folder2 /temp/folder3 using a script. I do not want to move these...

push back an object which has only move constructor to a vector

c++,c++11,vector,move
This is a rather general question. In this post Where does a std::vector allocate its memory? it says that vector allocates its elements in the heap by default. In C++11, there is move semantics and vector supports this. What if I have an object which has only move constructor, and...

pygame and sprite blur movement

pygame,sprite,move
I am struggling to move the sprite correctly. Instead of smooth move I can see blur move and I do not know how to solve it. Is there any chance you can point what I do incorrectly ? My target with it to drop the pizza so it hits the...

if i have T&& temp = std::move(other); then use this on a function that accepts T by value

c++11,move,move-semantics
so let's say i have a following function: void foo(std::string strParam) // pass-by-value { // function-body } so strParam of foo(string) will either be created via copy (if arg was lvalue) or move (if arg was rvalue). as everybody knows, foo("blah"); // rvalue; so string move constructor invoked for strParam....

Safely moving objects that run a lambda in a member thread that accesses other members

c++,c++11,lambda,move,swap
I have a class that has an std::thread member variable which runs a lambda function that depends on some other member variable. Let me give an example: struct C { C() { thread_ = std::thread([this]() { running_ = true; while (running_) { ... } }); } C(C&& rv) { swap(rv);...

Write records from one PF to another without READ operation or DOW loop or move operation.

copy,move,ibm-midrange,rpgle
I know how to copy records from one pf to another by reading one file in dow loop and writing into another file like below. Files are PF1 and PF2 having record format rec1 and rec2 respectively where each file have only one field named fld1 and @fld1 respectively- READ...

Should I return an rvalue reference parameter by rvalue reference?

c++,c++11,move
I have a function which modifies std::string& lvalue references in-place, returning a reference to the input parameter: std::string& transform(std::string& input) { // transform the input string ... return input; } I have a helper function which allows the same inline transformations to be performed on rvalue references: std::string&& transform(std::string&& input)...

Can a temporary object be passed by value without destroying the original in C++

c++,vector,move
In the following code, the pointer is reset when a struct S is destructed. I'd prefer a vector of structure values instead of pointers. Is there a way to add to the vector without the temporary getting destructed? int* pi = nullptr; struct S { S(int* i) { pi =...

How to move a UIView programmatically in Swift

swift,uiview,move
The issue is to move an "InfoView" (UIView) programmatically in Swift. The following constraints exist in the storyboard (see image): Now, I would like to move the "InfoView" inside "MyView" up or down. I tried: @IBOutlet weak var infoTextLabel: UILabel! @IBOutlet weak var infoTextLabelView: UIView! // set infoTextLabel color self.infoTextLabel.textColor...

How does the string move constructor work?

c++,string,memory,dynamic,move
I'm reading a book about c++ in an attempt to learn the language. there is this one example where it creates a vector-like class that only works with strings called stringV. the class defines a function called reallocate that should allocate new dynamic memory and moves its strings to the...

Preventing move semantics during pattern matching

pattern-matching,rust,move
I have a silly example here, just to demonstrate an issue I'm running into with another library and pattern matching. struct Person { name: String, age: i32, choice: Choices } #[derive(Debug)] enum Choices { Good, Neutral, Evil } fn find(p: Person) { match (p.choice, p.age) { (Choices::Good, a) if a...

How to ignore 8.3 filename for “move” command in batchscript?

windows,batch-file,cmd,move,short-filenames
I have to move a lot of xml-Files, named as follow: F010199004524001_904.XML F010199805946001_737.XML F010199904725001_611.XML F030390114543001_901.XML F030390114544001_257.XML F030390114545001_901.XML in my batch-file, there's this line: move C:\source\F01*.xml C:\target\F01\ Now I have the problem, that some of the files have a different 8.3-filename, for example "F030390114545001_901.XML" has the name "F01FCF~1.XML" so this file...

using std::move to prevent copying

c++,c++11,move
I have struct A struct A { std::vector<int> x; A() { std::cout << "A()" << std::endl; } A(const A&) { std::cout << "A(const A&)" << std::endl; } ~A() { std::cout << "~A()" << std::endl; } }; and struct B struct B : public A { std::vector<int> y; B() { std::cout...

Understanding Move Capture in Lambdas for C++11

c++,c++11,lambda,move,rvalue-reference
I have a question regarding the workaround proposed in order to address move capture in C++11 lambdas. In particular, taking the example from Meyer's book: std::vector<double> data; ... auto func = std::bind( [](const std::vector<double>& data) { /*uses of data*/ }, std::move(data) ); My question is: what would be the consequences/meaning...

Win7 Batch File - Moving Subfolders(& Files) to Grand-Parent Directory

batch-file,cmd,merge,move,subdirectories
I have a somewhat complicated problem. I've downloaded an archived website from archive.org using Httrack and now I have thousands of subfolders and files I need to merge before I can rebuild it. I'm trying to write a batch file to solve the problem. But my search results never come...

Moving a smart pointer from one unordered_set from another

c++11,move,shared-ptr,unique-ptr,unordered-set
template<class T> Class Node { //irrelavant functs }; class A { unordered_set<unique_ptr<Node<T>>, myHash<Node<T>>, myEqual<Node<T>>> nodes shared_ptr<A> child; void moveToChild() { for(auto it = nodes.begin(); it < nodes.end(); ++it) { if (some_cond) { child->nodes.emplace(std::move(*it)); } } } }; I have a class that holds bunch of nodes in unordered_set, and has...

Guaranteed Detection of Temporary->Named Points

c++,c++11,design,move,lazy-evaluation
Suppose you write a matrix class with some operations: class matrix { public: double operator()(size_t i, size_t j) const; ... }; matrix operator*(const matrix &lhs, const matrix &rhs); ... It makes sense to defer the evaluation of some matrix expressions: m0 * m1 * m2 * m3 * m4 (which...

Python pygame, moving an object

python,pygame,move
Ive been following a tutorial to learn pygame. I have this code to move an object in pygame. key = pygame.key.get_pressed() dist = 1 # distance moved in 1 frame, try changing it to 5 if key[pygame.K_DOWN]: # down key self.y += dist # move down elif key[pygame.K_UP]: # up...

Rvalue references without std::move [duplicate]

c++,c++11,move,rvalue-reference,move-constructor
This question already has an answer here: What are copy elision and return value optimization? 4 answers I have following class class widget { // The methods only print their name, i.e. c'tor, destructor etc. public: widget(); widget(const widget&); widget(widget&&); ~widget(); auto operator=(const widget&) -> widget&; auto operator=(widget&&) ->...

Tkinter : Moving more than one object at once

python,object,tkinter,move
I am still fairly new to tkinter and I am trying to create a network simulator. I have made a simpler version of my program without all of the extra network stuff. I have been stuck on a problem for quite a while now. I can't work out how to...

Perfect forwarding of primitive types

c++,move,rvalue-reference,primitive-types,perfect-forwarding
I need to implement some methods similar to vector::emplace for my own data structures. In the general case, I would implement them so that they support perfect forwarding, i.e., with rvalue-references, std::forward and that stuff. However, what if I know that all parameters to forward are primitive types such as...

Moving multiple files with gsutil

google-cloud-storage,move,gsutil
Let's say I've got the following files in a Google Cloud Storage bucket: file_A1.csv file_B2.csv file_C3.csv Now I want to move a subset of these files, lets say file_A1.csv and file_B2.csv. Currently I do this like that: gsutil mv gs://bucket/file_A1.csv gs://bucket/file_A11.csv gsutil mv gs://bucket/file_B2.csv gs://bucket/file_B22.csv This approach requires two call...

moving pacman in swift

swift,move,pacman
i am brand new to swift and i am trying to program a pacman. i am trying to move the pacman to the direction of the swipe, so far i have managed to move it to the edges of the screen, the problem is that when i try to move...

move redmine database to another instance

database,instance,move,redmine,migrate
I have redmine 2.5.3 installed on a virtual machine ( See Martin Denizet blog for HowTo install it ) Now, I want to move previous redmine DB (version 1.3) to this virtual machine. Both of redmine versions are in working , but virtual machine is not in production environment yet....

I can't download images uploaded ​​with “move_uploaded_file()” code on filezilla

php,html,image,move
When I use move_uploaded_file() code everything works fine and my files are being moved to my server. But later if I want to download those files from my server using filezilla, it says: "Could not start the transfer process" But i can download other files crate with imagejpeg() code. So...

How I can compare two Directories in Powershell and move the items then older x days?

powershell,recursion,compare,move,get-childitem
hi i want to compare two objects in Powershell. the objects are directories. For example: $folderA = gci $source -Recurse $folderB = gci $destination -Recurse $diff = Compare-Object -ReferenceObject $folderA -DifferenceObject $folderB -PassThru | Where-Object {$_.SlideIndicator -eq "<="} The first Problem is if folderB dont have elements then the object...