I work in an environment where, for historical reasons, we are using a hodgepodge of custom utility classes, most of which were written before STL arrived on the scene. There are many reasons why I think it is a good idea to at least write new code using STL, but the main one is that I believe it increases programmer productivity. Unfort...
I'm aware of the range iterators in boost, and as for this reference, it seems there should be an easy way of doing what I want, but it's not obvious to me.
Say I want to represent a numerical range, 0 to 100 (inclusive or not), say range(0,100). I would like to do something like:
for_each(range<int>(0,100).begin(), range<int>(0,100).e...
Hi,
i have the following template method,
template <class T>
void Class::setData( vector<T> data )
{
vector<T>::iterator it;
}
and i'm getting the following compilation error ( XCode/gcc )
error: expected `;' before 'it'
i found someone else with a similar problem here (read down to see it's the same even though it star...
I have a class that looks like this.
class A
{
public:
void doSomething();
}
I have an array of these classes. I want to call doSomething() on each item in the array. What's the easiest way to do this using the algorithms header?
...
I need to designe predicate for stl algorithms such as find_if, count_if.
namespace lib
{
struct Finder
{
Finder( const std::string& name ):
name_( name )
{
}
template< typename TElement >
bool operator( const TElement& element )
{
return element.isPresent(...
Searched for a while, but I can't figure out why this would raise a bus error.
Any help would be much appreciated.
typedef struct {
set<int> pages;
} someStruct;
...
void someFunction() {
...
someStruct *a = createSomeStruct(); // just mallocs and returns
a->pages.insert(5);
...
}
...
Hi Folks,
I have a source container of strings I want to remove any strings from the source container that match a predicate and add them into the destination container.
Remove_copy_if and other algorithms can only reorder the elements in the container, and therefore have to be followed up by the erase member function. My book (Josutti...
Hi!
I'm using quite much STL in performance critical C++ code under windows. One possible "cheap" way to get some extra performance would be to change to a faster STL library.
According to this post STLport is faster and uses less memory, however it's a few years old.
Has anyone made this change recently and what were your results?
...
I am passing my vector to a function that expects a c array. It returns the amount of data it filled (similar to fread). Is there a way i can tell my vector to change its size to include the amount that function has passed in?
of course i make sure the vector has the capacity() to hold that amount of data.
...
Many times, I find myself having to define a container for multi-dimensional data.
Let's take an example: I have many Chips, each Chip has many Registers, each Register has many Cells, and each Cell has many Transistors.
At some stage of my C++ program I have to read this data, and later I have to use it.
I cannot use any external sto...
Will the array be deallocated and if so, what is a workaround?
double * GetArrayFromVector( std::map<std::string, double> m, char ** names, int count )
{
if(!names) return 0;
std::vector<double> vec(m.size());
for (int i=0; i<count; ++i)
{
if(!names[i]) return 0;
std::map<std::string, double>::iterator i...
I'm new to debugging with Eclipse.
I try to debug my app to know where it segfaults.
The problem is that Eclipse breaks within the STL, which is very annoying.
For example: I created a breakpoint in my source file on line 134, which works fine
but if I hit F6 for "Step Over", Eclipse/gdb breaks in basic_string constructor used in the ...
What is the benefit of inheriting from std::binary_function (or std::unary_function)?
For example I have such code:
class Person
{
public:
Person();
Person(int a, std::string n);
Person(const Person& src);
int age;
std::string name;
};
Person::Person()
: age(0)
, name("")
...
I couldn't find any definitive answer to this question.
I suppose most implementation use merge sort that is stable but, is the stability a requirement or a side effect?
...
is there any tristate type in c++ stl?
...
I need to write a templated function replace_all in C++ which will take a string, wstring, glibmm::ustring etc. and replace all occurrences of search in subject with replace.
replace_all.cc
template < class T >
T replace_all(
T const &search,
T const &replace,
T const &subject
) {
T result;
type...
Need prettier solution of below example but with std::accumulate.
#include <algorithm>
#include <vector>
#include <iostream>
class Object
{
public:
Object( double a, double b ):
a_( a ),
b_( b )
{}
double GetA() const { return a_; }
double GetB() const { return b_; }
// other methods
private:
do...
I want to create an adjacency matrix for a graph. Since I read it is not safe to use arrays of the form matrix[x][y] because they don't check for range, I decided to use the vector template class of the stl. All I need to store in the matrix are boolean values. So my question is, if using std::vector<std::vector<bool>* >* produces too mu...
Hi, I'm currently using vectors as c-style arrays to send and recieve data through Winsock.
I have a std::vector and I'm using that as my 'byte array'.
The problem is, I'm using two vectors, one for each send, and one for each recv, but what I'm doing seems to be fairly inefficient.
Example:
std::string EndBody("\r\n.\r\n");
std::fil...
I tried to find a place where I can find ready to copy list of all functions and classes available in each stl header file.
Looking through /usr/include/c++ is not so convenient as I expected.
Google very often shows
http://www.cplusplus.com/reference/
which is not so convenient to copy and paste.
Does anyone knows a good place to lo...