stl

What is the byte alignment of the elements in a std::vector<char> ?

I'm hoping that the elements are 1 byte aligned and similarly that a std::vector<int> is 4 byte aligned ( or whatever size int happens to be on a particular platform ). Does anyone know how standard library containers get aligned? ...

Comparison of C++ STL collections and C# collections?

I'm still learning C# and was surprised to find out that a List<T> is much more like a std::vector than a std::list. Can someone describe all the C# collections in terms of the STL (or if STL comparisons are difficult, standard conceptual data types with Wikipedia links? I expect the reference would be widely useful. A minimal list of...

Merge two STL vectors with an alternation pattern

I have two STL vectors A and B and need to merge them into a third one, where the elements should be ordered in a way, that every nth element in the output vector should be of vector B. My current code looks something like this: std::vector<int> a(10, 4); std::vector<int> b(10, 8); std::vector<int> c; static const std::size_t STEP(3); ...

std::vector is so much slower than plain arrays?

I've always thought it's the general wisdom that std::vector is "implemented as an array," blah blah blah. Today I went down and tested it, seems to be not so: Here's some test results: UseArray completed in 2.619 seconds UseVector completed in 9.284 seconds UseVectorPushBack completed in 14.669 seconds The whole thing completed in 26....

Only one evaluation guaranteed for std::min/std::max

Does the C++ standard guarantee that the call c = std::min(f(x), g(x)); evaluates the functions f and g only once? ...

stl and exceptions

Hi, If I use reserve() to reserve enough elements for a vector, will push_back() (or insert()) throw any exceptions? Is there a reference somewhere that specifies which stl function throw / not throw any exceptions? Thank you. ...

Can I detach a std::vector<char> from the data it contains?

I'm working with a function which yields some data as a std::vector<char> and another function (think of legacy APIs) which processes data and takes a const char *, size_t len. Is there any way to detach the data from the vector so that the vector can go out of scope before calling the processing function without copying the data contain...

Need to join opensource project for a newbie

Possible Duplicate: C++ OpenSource project for beginner programmer? How to find opensource projects looking for help ? OpenSource Projects - Is there a site which lists projecs that need more developers? hi all, I am a newbie and I need to join a open source project to contribute and enhance my C++ skills. Anyone got a id...

STL: convoluting two unary_function arguments

Working on Windows with VS2005 and struggling to understand the error messages I'm getting. If this question has been asked before, I'm sorry. I couldn't find it. Class I'm testing: #include <functional> using std::unary_function; template<typename F, typename G> struct UnaryConvolution : unary_function<typename G::argument_type,typ...

inserting "this" into an STL map from the constructor

VERSION 1 class Doh { private: static std::map<const std::string, const Doh*> someMap; std::string stringValue_; public: Doh(std::string str) : stringValue_(str) { Doh::someMap.insert( std::make_pair<const std::string,const Doh*> (this->stringValue_,this) ); } } The above wa...

Peek the next element in STL container

is it possible to peek next element in a container which the iterator currently points to without changing the iterator? For example in std::set, int myArray[]= {1,2,3,4}; set <int> mySet(myArray, myArray+4); set <int>::iterator iter = mySet.begin(); //peek the next element in set without changing iterator. mySet.erase(iter); //erase...

Is std::array<T, S> guaranteed to be POD if T is POD?

I'm currently writing a C++ memory editing library and for the read/write APIs I use type traits (std::is_pod, std::is_same) and boost::enable_if to provide 3 overloads: POD types. e.g. MyMem.Read(SomeAddress); String types. e.g. MyMem.Read>(SomeAddress); (This doesn't actually read out a C++ string, it reads out a C-style string and c...

Overloading functions not compiling

Hi guys, I am following the book C++ Cookbook from O'Reilly and I try one of the examples, here is the code: #include <string> #include <iostream> #include <cctype> #include <cwctype> using namespace std; template<typename T, typename F> void rtrimws(basic_string<T>& s, F f){ if(s.empty()) return; typename basic_strin...

Boost: Function Output Iterator, reinventing the wheel

Normally someone would just go and grab Boost's Function Output Iterator but I'm not allowed to use Boost at work. That said, I just want to use the copy function to traverse a collection, call a function on each item, take the output of that function, and finally push_back it onto another collection. I've written some code: #include ...

Writing algorithm functions for STL

I have a std::set which is of type point struct point { int x; int y; int z; }; Suppose I want to perform three different operation on each variable in set i.e Find the smallest number from x variables. Get missing elements from y variables using set difference. Get product of all z variables. At this point, should i use thr...

C++ valgrind possible leaks on STL string

Hi, I do not see the reason of the leak below. #include <iostream> #include <cstdlib> int fail(const std::string str) { std::cerr<< str << std::endl; exit(1); } const std::string usage() { std::string a = "a"; return a; } int main() { fail(usage()); return 0; } Valgrind says: ==7238== 14 bytes in 1 bloc...

Can I Have Polymorphic Containers With Value Semantics in C++0x?

This is a sequel to a related post which asked the eternal question: Can I have polymorphic containers with value semantics in C++? The question was asked slightly incorrectly. It should have been more like: Can I have STL containers of a base type stored by-value in which the elements exhibit polymorphic behavior? If you ar...

std intellisense in VS2010

I just noticed that eclipse has a extensive intellisense for stl. If you hover over any stl function or object you get information similar to what you would find in a c++ stl reference. This is however not the case in VS2010 and I'm wondering if there is any good plugin that might enable this? and even more far fetched... for boost as w...

Should I return an iterator or a pointer to an element in a STL container?

I am developing an engine for porting existing code to a different platform. The existing code has been developed using a third party API, and my engine will redefine those third party API functions in terms of my new platform. The following definitions come from the API: typedef unsigned long shape_handle; shape_handle make_new_sh...

C++ vector, return vs. parameter

Possible Duplicate: how to return an object in C++ I am wondering if there is a difference between the three following approaches: void FillVector_1(vector<int>& v) { v.push_back(1); // lots of push_backs! } vector<int> FillVector_2() { vector<int> v; v.push_back(1); // lots of push_backs! return v; } vector...