stl

Where can I find the function definition in atomicity.h?

a 夏天 提交于 2019-12-24 05:13:10
问题 atomicity.h is part of c++ stl. In its source file, it declares two functions about atomic operation. Here is the whole source code. Where can I find the definition of these functions. I don't find it in stl source code. #ifndef _GLIBCXX_ATOMICITY_H #define _GLIBCXX_ATOMICITY_H 1 #include <bits/atomic_word.h> namespace __gnu_cxx { _Atomic_word __attribute__ ((__unused__)) __exchange_and_add(volatile _Atomic_word* __mem, int __val); void __attribute__ ((__unused__)) __atomic_add(volatile

Unable to access non-const member functions of objects in C++ std::set

瘦欲@ 提交于 2019-12-24 05:06:19
问题 Message is a class I made. I have a set of them in the main function that I pass to messageTimeOut (and some other functions). In messageTimeOut using an itorator I am looping through them and accessing different member functions. However, I can only access const member functions of the Message pointed to by the iterator. If I try to access non const member functions I get the error: “In function 'void messageTimeOut(threadParameters*)': main.cpp:74:33: error: passing 'const Message' as 'this

C++/STL string: How to mimic regex like function with wildcards?

↘锁芯ラ 提交于 2019-12-24 04:58:11
问题 I would like to compare 4 character string using wildcards. For example: std::string wildcards[]= {"H? ", "RH? ", "H[0-5] "}; /*in the last one I need to check if string is "H0 ",..., and "H5 " */ Is it possible to manage to realize only by STL? Thanks, Arman. EDIT: Can we do it without boost.regex? Or should I add yet another library dependences to my project?:) 回答1: Use Boost.Regex 回答2: No - you need boost::regex 回答3: Regular expressions were made for this sort of thing. I can understand

RInside example build using clang++ on OS X Mavericks cannot find STL standard library on linking

你。 提交于 2019-12-24 04:28:07
问题 I recently moved to C++11 and Xcode 5 with command line tools on OS X 10.9.1, installed boost 1.55 using Homebrew and changed the compiler from g++ to clang++ (as mentioned in this post: Error when with Xcode 5.0 and Rcpp). The compiler change fixed Rcpp when running in R. But I am having issues with compiling the RInside examples (which used to work just fine). I re-downloaded RInside and unzipped the tar, went to the examples/standard directory and did a make clean and make all . It looks

Using an STL Iterator without initialising it

℡╲_俬逩灬. 提交于 2019-12-24 03:45:13
问题 I would like to do something like this: container::iterator it = NULL; switch ( eSomeEnum ) { case Container1: it = vecContainer1.begin(); break; case Container2: it = vecContainer2.begin(); break; ... } for( ; it != itEnd ; ++it ) { .. } But I can't create and initialise an iterator to NULL. Is there some way I can do this? Ideally I would just create and assign the iterator in the switch, but then it would go out of scope immediately. 回答1: You just needn't initialize it at all, because

convert std::ostream to some array?

廉价感情. 提交于 2019-12-24 03:44:08
问题 I have a legacy library that takes data from hardware and writes it to ostream . The method looks like following : int sensors(ostream*) const; I am not skilled enough in Ancient Ways. How to convert this data to QByteArray ? Or, at least, to char array of known size? I would have solved it myself, but there is an additional problem: the data in ostream seem to be arbitrary length and have several arbitrary '\0' symbols, so you can't count on it being null-terminated. 回答1: I think this is

I need copyable buffer, as light as possible (e.g. not zero initialized)?

拟墨画扇 提交于 2019-12-24 03:25:49
问题 I need raw buffers of very big size (let say more MB than KB) as light as possible. I would like to have it keep the data in dynamic area, not necessarily it shall be grow-able, I will set the size at construction. I thought about std::vector<unsigned char> but: std::vector<unsigned char> a(VERY_BIG_SIZE); has the data initialized to 0 - I don't need this, I don't want to pay for it... This is embedded system already of high usage of CPU/RAM and I want to benefit from the fact that memory

Finding a value of range less than or greater than from container class

匆匆过客 提交于 2019-12-24 03:04:06
问题 Currently, I have a std::map <DWORD, DWORD> table and I'm looking for a key value matching a specific range. For example: Find a key value from map whose value should be either less than < 50 or greater than > 50 from the searched key value. If the searched key value was 20 then I would want a key value of range from map i.e -70.............20............+70 is there a better way to find a key value other than using two loop (first for less than, second for greater than) or an appropriate way

Does the address of the result of std::string::operator[] point to a writable, nul-terminated buffer?

雨燕双飞 提交于 2019-12-24 02:47:10
问题 I am modifying a function that accepts a const char* and uses a function, ProcessString. ProcessString is a function that expects a null-terminated character buffer as a char*. The characters in the buffer may or may not be modified, as defined by the function signature below. To "bridge the gap", I am using a temporary std::string: void ProcessString( char* str ); void SomeFunction( const char* str ) { string temp(str); ProcessString( &temp[0] ); } My primary question is about the guarantees

Use cout or cerr to output to console after it has been redirected to file

折月煮酒 提交于 2019-12-24 01:47:10
问题 Redirecting cout or cerr to a file is easy enough. I can use this to redirect third party output to a file. However, after I have redirected the third party output to a file, how do I then use cout myself to output to the console? 回答1: I'm a great fan of RAII, so I once wrote this small helper class. It will redirect the stream until it goes out of scope, at which point it restores the original buffer. Quite handy. :) class StreamRedirector { public: explicit StreamRedirector(std::ios& stream