In attempting to use std::select1st from <functional> in a VS2008 project I found that it was ifdef'd out by a _HAS_TRADITIONAL_STL guard.
Is there a reason for this?
Is it safe to simply define _HAS_TRADITIONAL_STL before including <functional>?
...
I know this is probably a silly question.. When would I need to write my own iterator? Is it just when designing my own container class? Are there any other times when I would want to create my own iterator?
Examples would be appropriated.
-Jon
...
I have a traits class that's used for printing out different character types:
template <typename T>
class traits {
public:
static std::basic_ostream<T>& tout;
};
template<>
std::ostream& traits<char>::tout = std::cout;
template<>
std::wostream& traits<unsigned short>::tout = std::wcout;
gcc (g++) version 3.4.5 (yes somewhat old) i...
Hi, people.
I try to use openmp for multithreading the loop through std::set. When I write the following code -
#pragma omp parallel for
for (std::set<A>::const_iterator i = s.begin(); i != s.end(); ++i) {
const A a = *i;
operate(a);
}
I get an error -
error: invalid type for iteration variable 'i...
I've been programming c++ for about a year now and when i'm looking about i see lots of references to STL.
Can some one please tell me what it does?
and the advantages and disadvantageous of it?
also what does it give me over the borlands VCL or MFC?
thanks
...
When should I choose one over the other.
Are there any pointers that you would recommend for using the right STL containers.
...
I am trying to pass a value from C++ to TCL. As I cannot pass pointers without the use of some complicated modules, I was thinking of converting a vector to a char array and then passing this as a null terminated string (which is relatively easy).
I have a vector as follows:
12, 32, 42, 84
which I want to convert into something l...
Just a stupid question .
I have a
std::vector<SomeClass *> v;
in my code and i need to access its elements very often in the program, looping them forward and backward .
Which is the fastest access type between those two ?
Iterator access
std::vector<SomeClass *> v;
std::vector<SomeClass *>::iterator i;
std::vector<SomeClass *>:...
More specifically, does NDK have a complete STL implementation. We're looking at this for devices running 1.6 and upwards.
...
I want to insert n elements into a map where n is known ahead of time. I do not want memory allocation at each insertion. I want all memory allocation at the beginning. Is there a way to do this? If so, how? Will writing some sort of memory allocator help?
I ran GMan's code and got the following output. GetMem is printed from a call to ...
I've stumbled upon what I believe is a bug in the stl algorithm advance.
When I'm advancing the iterator off of the end of the container, I get inconsistent results. Sometimes I get container.end(), sometimes I get the last element. I've illustrated this with the following code:
#include <algorithm>
#include <cstdio>
#include <set>
...
So, I have two structs:
struct coordinate {
float x;
float y;
}
struct person {
int id;
coordinate location;
}
and a function operating on coordinates:
float distance(const coordinate& c1, const coordinate& c2);
In my main method, I have the following code:
map<int,person> people;
// populate people
map<int,map<fl...
I'd like to use iterators from an STL list as keys in a map. For example:
using namespace std;
list<int> l;
map<list<int>::const_iterator, int> t;
int main(int argv, char * argc) {
l.push_back(1);
t[l.begin()] = 5;
}
However, list iterators do not have a comparison operator defined (in contrast to random acc...
I have a code that looks something like:
struct Data { int value; };
class A {
public:
typedef std::deque<boost::shared_ptr<Data> > TList;
std::back_insert_iterator<TList> GetInserter()
{
return std::back_inserter(m_List);
}
private:
TList m_List;
};
class AA {
boost::scoped_ptr<A> m_a;
public:
AA()...
#include <iostream>
#include <algorithm>
#include <vector>
#include <boost/array.hpp>
#include <boost/bind.hpp>
int main() {
boost::array<int, 4> a = {45, 11, 67, 23};
std::vector<int> v(a.begin(), a.end());
std::vector<int> v2;
std::transform(v.begin(), v.end(), v2.begin(),
boost::bind(std::multiplies<int>(), _1, 2));
st...
Given
std::vector<CMyClass> objects;
CMyClass list[MAX_OBJECT_COUNT];
Is it wise to do this?
for(unsigned int i = 0; i < objects.size(); list[i] = objects.at(i++));
Or should I expand my loop to this?
for(unsigned int i = 0; i < objects.size(); i++)
{
list[i] = objects.at(i);
}
...
I'm porting some C++ code to C#.
Does C# have an equivalent to std::nth_element() or do I need to roll my own?
...
I couldn't find a download-to-print version of the Apache C++ Standard Library User Guide anywhere - the only options available are the frames and no-frames versions online. Writing a script to wget and collate them seems overkill.
Does anyone know if a downloadable-to-print PDF or other formats exist - and if not, why not?
PS - I rea...
Hello everyone,
Can any of STL algorithms/container operations like std::fill, std::transform be executed in parallel if I enable OpenMP for my compiler? I am working with MSVC 2008 at the moment.
Or maybe there are other ways to make it concurrent?
Thanks.
...
list<int> foo;
list<int> foo2;
list<int>::iterator foo_end = foo.end();
list<int>::iterator foo2_end = foo2.end();
for (list<int>::iterator it = foo.begin(); it != foo2_end; ++foo) <- notice != comparison here
{
...
it this allowed? will it work correctly.
I am inclined to think that this is implementation dependent, anyone knows ...