stl

Case insensitive std::string.find()

I am using std::string's find() method to test if a string is a substring of another. Now I need case insensitive version of the same thing. For string comparison I can always turn to stricmp() but there doesn't seem to be a stristr(). I have found various answers and most suggest using Boost which is not an option in my case. Addition...

question about std::vector::end()

I recently finished fixing a bug in the following function, and the answer surprised me. I have the following function (written as it was before I found the bug): void Level::getItemsAt(vector<item::Item>& vect, const Point& pt) { vector<itemPtr>::iterator it; // itemPtr is a typedef for a std::tr1::shared_ptr<item::Ite...

boost::iterator_facade and std::find(...)

Below is an implementation of an iterator_facade for a linked list node. It's pretty much the same as that presented in the docs except it has a Value* dereference type instead of Value&. The problem is with using the iterators with std::find, it throws these compile errors for the find template. edit One Several noted that std::find ...

c++ STL queues, references and segmentation fault

Newbie to C++ learning by converting a java program to c++. The following code results in a segmentation fault (SIGSEGV) when executed. //add web page reference to pages queue (STL) void CrawlerQueue::addWebPage(WebPage & webpage) { pagesBuffer.push(webpage); } //remove and return web page reference from pages queue WebPage & Crawl...

Passing std::string in a library API

We are currently building an API for a certain library. Part of the interface requires the library to get and return to the user classes such as vector and string. When trying to simulate use of the library in a simple scenario, in debug mode the system crush when delivering a string as an input. I believe there is a different represen...

non-resizeable vector/array of non-reassignable but mutable members?

Is there a way to make a non-resizeable vector/array of non-reassignable but mutable members? The closest thing I can imagine is using a vector<T *> const copy constructed from a temporary, but since I know at initialization how many of and exactly what I want, I'd much rather have a block of objects than pointers. Is anything like wha...

C++ Coding Logic - Various Ideas

I want to write a method to determine if a given string is a palindrome. E.g. "Madam I'm Adam", or "A man, a plan, a canal, Panama". The prototype for the function is: bool is_palindrome(char const * str) I have a simple logic to check for equality by moving forward & backward from extreme ends of the string. But, i would like to ...

C++ - Single Linked List - Ideas

I want to write a method to remove consecutive items with duplicate data values from a singly linked list. The method should return the number of items removed. The method should clean up memory as required, and should assume that memory was allocated using new. For example, passing in the list ->a->b->c->c->a->b->b->b->a->null should ...

Standard C++ libraries headers on gnu gcc site..

Hi all, I want to browse the source code of gnu implementation of C++ standard libraries -- header files as well as the implementation. I have landed myself into: http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.4/index.html My first step was to look header file at: http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-ht...

A quick question on stack impl of C++ standard library

Hi, What does the line: template<typename _Tp1, typename _Seq1> friend bool operator==(const stack<_Tp1, _Seq1>&, const stack<_Tp1, _Seq1>&); in http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.4/a01367.html do? Why is _Tp1 repeated twice in arguements list? Thanks, ...

How to create a generic container with unknown member functions?

Dear reader, I noticed that I'm often in the need of a container class. For example when working on a particle system, I create a container class Particles which has a member vector<Particle*>. Then I call: Particles* my_particles like my_particles->draw(), and in the Particles.draw() I iterator over the vector<Particle*> and call draw...

c++ container search by key and value

I'm trying to build a container of string representations of ordinal numbers, searchable both by the string and by the number. For example, I can do it trivially, but inefficiently, with an array: std::string ordinalStrings = {"zeroth", "first", "second",..} getting the string with ordinalStrings[number], and the integer with a while(...

How do i make a some sort of istream for a vector of unsigned chars

hello how can i create an istream from a buffer unsigned char* or vector. basically i want : void Func(vector<unsigned char> data) { someSortOfIstream x (data); x >> something; } using boost too.... ...

STL container function return values

When looking over the member functions of the STL containers, an odd thought occurred to me. Why don't functions like std::vector<T>::push_back(T) not have an (optional) return value (iterator or even a reference to the appended object)? I know std::string functions like insert and erase return iterators, but that's for obvious reasons. ...

Why are C++ STL iostreams not "exception friendly"?

I'm used to the Delphi VCL Framework, where TStreams throw exceptions on errors (e.g file not found, disk full). I'm porting some code to use C++ STL instead, and have been caught out by iostreams NOT throwing exceptions by default, but setting badbit/failbit flags instead. Two questions... a: Why is this - It seems an odd design decis...

Problems with remove_if in VS2010 when using sets

I have the following code. #include <set> #include <algorithm> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { typedef set<long> MySet; MySet a; for( int i = 0; i < 10; ++i) { a.insert(i); } MySet::iterator start,end,last; start = a.begin(); end = a.end(); last = remove_if(start,end,bind2nd(less_equal<long>...

Writing stl compatible iterators

I'm trying to convert an iterator class I have to be stl compatible so that it can be used with the stl algorithms. In the following simple (and frankly useless) example, which should print the values 0 to 5 inclusive, I am getting the following errors, ISO C++ forbids incrementing a pointer of type ‘Iterator (*)()‘ and, invalid conve...

How to combine a function and a predicate in for_each ?

How can you call a Function over some part of a container, using for_each() ? I have created a for_each_if() to do a for( i in shapes ) if( i.color == 1 ) displayShape(i); and the call looks like for_each_if( shapes.begin(), shapes.end(), bind2nd( ptr_fun(colorEquals), 0 ), ...

CRT types across process boundaries

I'm doing drag/drop out of an activeX control. On drag, I provide a CComQIPtr which has COM methods implemented to pass information to the drop target. On drop, the drop target's process calls my COM methods to get information. Am I not allowed to use CRT types or pointers to CRT types near that interface boundary? I would love for my I...

When should the STL algorithms be used instead of using your own?

I frequently use the STL containers but have never used the STL algorithms that are to be used with the STL containers. One benefit of using the STL algorithms is that they provide a method for removing loops so that code logic complexity is reduced. There are other benefits that I won't list here. I have never seen C++ code that ...