stl

call to constructor can be considered as function declaration?

橙三吉。 提交于 2019-12-23 12:28:30
问题 The next few lines I'm going to write come from the book "The C++ Standard Library - A tutorial and reference". Initialize by using standard input: //read all integer elements of the deque from standard input std::deque<int> c((std::istream_iterator<int>(std::cin)), (std::istream_iterator<int>())); Don't forget the extra parentheses around the initializer arguments here. Otherwise, this expression does something very different and you probably will get some strange warnings or errors in

C++ To call member function in for_each for items in the member container

徘徊边缘 提交于 2019-12-23 12:09:51
问题 If I have a class (that mimic some of STL's container) like this: class Elem { public: void prepare(); // do something on *this // ... }; class Selector { public: typedef vector<Elem *> container_type; typedef container_type::iterator iterator; iterator begin() { return cont_.begin(); } iterator end() { return cont_.end(); } void check_all(); private: prepare_elem(Elem *p); // do something on 'p' container_type cont_; }; If I want to call prepare() for all elements in 'cont_', I could make

Find if an item already exists in STL queue

无人久伴 提交于 2019-12-23 12:07:56
问题 I am using an STL queue to implement a BFS (breadth first search) on a graph. I need to push a node in the queue if that node already doesn't exist in the queue. However, STL queue does not allow iteration through its elements and hence I cannot use the STL find function. I could use a flag for each node to mark them when they are visited and push them only when the flag is false, however, I need to run BFS multiple times and after each time I will have to reset all the flags, so I ended up

stl compliant container

自古美人都是妖i 提交于 2019-12-23 11:51:13
问题 I've been curious as to what entails an stl-compliant container (or boost-compliant, my understanding is that their either the same, or very similar). I've seen a few examples of what people call stl-compliant (for example, this one over at codeproject, and obviously the actual stl containers), but I'm not exactly sure what components of those containers I need to have. From what i could gather, I need at least these things: STL-compliant Iterators (the current stl only uses bi-directional or

stl compliant container

情到浓时终转凉″ 提交于 2019-12-23 11:50:06
问题 I've been curious as to what entails an stl-compliant container (or boost-compliant, my understanding is that their either the same, or very similar). I've seen a few examples of what people call stl-compliant (for example, this one over at codeproject, and obviously the actual stl containers), but I'm not exactly sure what components of those containers I need to have. From what i could gather, I need at least these things: STL-compliant Iterators (the current stl only uses bi-directional or

How can I check via macro whether the GNU libstdc++ is used?

百般思念 提交于 2019-12-23 11:47:35
问题 How can I check via macro whether the (GNU GCC) libstdc++ STL implementation is used? Is that possible? I would like to have that working in both GCC and Clang. For C++11 on Linux, it's probably anyway the only choice (or is it?). (STLport doesn't have C++11 support, AFAIK.) On MacOSX, (LLVM) libc++ STL is more likely, if you use Clang (maybe also for GCC, not sure). 回答1: You can check for __GLIBCXX__ (or __GLIBCPP__ , for releases before 3.4.0) macro existence, after including one of the C++

How can I check via macro whether the GNU libstdc++ is used?

十年热恋 提交于 2019-12-23 11:47:07
问题 How can I check via macro whether the (GNU GCC) libstdc++ STL implementation is used? Is that possible? I would like to have that working in both GCC and Clang. For C++11 on Linux, it's probably anyway the only choice (or is it?). (STLport doesn't have C++11 support, AFAIK.) On MacOSX, (LLVM) libc++ STL is more likely, if you use Clang (maybe also for GCC, not sure). 回答1: You can check for __GLIBCXX__ (or __GLIBCPP__ , for releases before 3.4.0) macro existence, after including one of the C++

std::back_inserter needs const_reference on older GCC. Why?

我只是一个虾纸丫 提交于 2019-12-23 11:46:41
问题 I am currently looking at some code that can be compiled on newer versions of GCC but not on older ones. In my case I am using a std::back_inserter to std::copy some data from one data structure to a custom data structure. If I forget the typedef value_type & const_reference typedef in this custom data structure however, this will not compile on GCC 4.4. The same code compiles and runs just fine on GCC 4.5. What is the difference in between these two compiler versions, that makes the code

C++ Design Pattern for allocator type arguments

那年仲夏 提交于 2019-12-23 10:57:30
问题 The C++03 standard library uses simple template type arguments when passing a type to a class which is meant to be an allocator. This is possible because of how templates work in C++. However, it isn't very straightforward and you might don't know what exactly the type definition should look like - especially in case of non standard types. I thought it might be a good idea to use adaptor classes instread. I've created an example to show you what I mean: #ifndef HPP_ALLOCATOR_ADAPTOR_INCLUDED

Problems using a map with a bitset as a key

不羁岁月 提交于 2019-12-23 10:57:09
问题 I am trying to create a map in C++ with bitset as a key. However the compiler generates the following error messages In file included from /usr/include/c++/4.6/string:50:0, from /usr/include/c++/4.6/bits/locale_classes.h:42, from /usr/include/c++/4.6/bits/ios_base.h:43, from /usr/include/c++/4.6/ios:43, from /usr/include/c++/4.6/ostream:40, from /usr/include/c++/4.6/iostream:40, from test2.cpp:1: /usr/include/c++/4.6/bits/stl_function.h: In member function ‘bool std::less<_Tp>::operator()