std

How to sort two arrays/vectors in respect to values in one of the arrays, using CUDA/Thrust

纵然是瞬间 提交于 2019-12-07 07:05:23
问题 This is a conceptual question in regards programming. To summarize, I have two arrays/vectors and I need to sort one with the changes propagating in the other as well, so that if I sort arrayOne, for each swap in the sort - the same thing happens to arrayTwo. Now, I know that std::sort allows you to define a comparison function (for custom objects I assume) and I was thinking of defining one to swap arrayTwo at the same time. So what I want is - to sort the two vectors based on values in one

How to derive from C++ std::basic_ostream and make the << operator virtual?

£可爱£侵袭症+ 提交于 2019-12-07 06:18:22
问题 I am writing a class that has various messages output. I want to make this class general and platform independent, so I am thinking of passing a basic_ostream reference to it and it can dump all the messages into the stream. By doing this, if the class is used in a console program, I can pass std::cout to it and display in console window. Or I could pass a derived ostream to it and redirect the message to some UI components, e.g. ListBox? The only problem is the data inserter operator << is

Throwing an exception from std::call_once

戏子无情 提交于 2019-12-07 05:04:41
问题 The C++ Standard states the following about the execution of std::call_once with functions that throw exceptions (§30.4.4.2/2): 2/ Effects: An execution of call_once that does not call its func is a passive execution. An execution of call_once that calls its func is an active execution. An active execution shall call INVOKE (DECAY_- COPY ( std::forward(func)), DECAY_COPY (std::forward(args))...). If such a call to func throws an exception the execution is exceptional, otherwise it is

std::any across shared library bounding in mingw

白昼怎懂夜的黑 提交于 2019-12-07 04:12:32
问题 I stumbled about an issue while using libstdc++'s std::any implementation with mingw across a shared library boundary. It produces a std::bad_any_cast where it obviously should not (i believe). I use mingw-w64, gcc-7 and compile the code with -std=c++1z. The simplified code: main.cpp: #include <any> #include <string> // prototype from lib.cpp void do_stuff_with_any(const std::any& obj); int main() { do_stuff_with_any(std::string{"Hello World"}); } lib.cpp: Will be compiled into a shared

Best way to delete a std::unique_ptr from a vector with a raw pointer?

一个人想着一个人 提交于 2019-12-07 03:46:33
问题 So I have a vector like so: std::vector<std::unique_ptr<SomeClass>> myVector; Then I have another vector which contains raw pointers of SomeClass : std::vector<SomeClass*> myOtherVector; If there is an element inside myOtherVector it will also be inside myVector , so I want to go through each element in myOtherVector and remove the same element from myVector . Then clear out the vector. This is what I came up with: for(size_t i = 0; i < myOtherVector.size(); i++) { myVector.erase(std::remove

'powf' is not a member of 'std'

匆匆过客 提交于 2019-12-07 03:11:41
问题 Hi i have this error on a library that i have to compile for XCode. The <cmath> is included. Can someone explain to me what is going wrong ? Thanks. 回答1: Up until C++11, powf was just a Microsoft-ism. It did not appear in the ISO standard at all so is unlikely to be in XCode unless they were to adapt Microsoft's bizarre practices, something I would think unlikely. pow , on the other hand, has been part of the C++ library for longer by virtue of the fact that it's in earlier iterations of the

iterate through two std::lists simultaneously

橙三吉。 提交于 2019-12-07 01:52:43
问题 Sorry if this is too simple a question. Prior error checking ensures l1.size() == l2.size() . std::list<object1>::iterator it1 = l1.begin(); std::list<object2>::iterator it2 = l2.begin(); while(it1 != l1.end() && it2 != l2.end()){ //run some code it1++; it2++; } Is this a reasonable approach, or is there a more elegant solution? Thanks for your help. 回答1: I prefer to use for if increments unconditionally occurs: for(; it1 != l1.end() && it2 != l2.end(); ++it1, ++it2) { //run some code } You

Thread in C++ in MacOS X

删除回忆录丶 提交于 2019-12-07 00:28:20
问题 I'm trying to run some code using threads in standard C++ (installed with XCode) in MacOS X Mavericks. But I'm getting some errors. Here's a minimal working example: #include <thread> #include <iostream> void run (int x) { std::cout<<"."; } int main (int argc, char const *argv[]) { std::thread t(run); } The error I'm getting: minimal.cpp:10:17: error: no matching constructor for initialization of 'std::thread' std::thread t(run,0); ^ ~~~~~ /Applications/Xcode.app/Contents/Developer/Toolchains

Function for calculating the mean of an array double[] using accumulate

∥☆過路亽.° 提交于 2019-12-06 23:26:31
问题 It must be the most common function for what everyone has a code snippet somewhere, but I have actually spent no less than 1.5 hour searching for it on SO as well as on other C++ sites and have not found a solution. I would like to calculate the mean of a double array[] using a function . I would like to pass the array to the function as a reference . There are millions of examples where the mean is calculated in a main() loop, but what I am looking for is a function what I can put in an

Undefined symbols for architecture x86_64 c++ on Mac

浪尽此生 提交于 2019-12-06 23:08:56
问题 Hi I have wrote a program in C++ in Netbeans on Macintosh that uses these these includes - iostream,fstream, string & cstdlib. The program compiles fine in Netbeans but I need to compile and run it with gcc because I need to pass an Image File to the program in terminal. When I try to compile I get the error below and to be honest I am completely lost as to what is going on. It seems there is an issue with the namespace? Anyone able to help? Thanks! Macintosh-2:ImageTool root$ gcc main.cpp -o