Questions tagged [std]

The C++ Standard Library, and its namespace. Use in conjunction with [c++].

From Wikipedia

The C++ Standard Library provides several generic containers, functions to utilise and manipulate these containers, function objects, generic strings and streams (including interactive and file I/O).

http://en.wikipedia.org/wiki/C++_Standard_Library

The concept of using namespaces

http://en.wikipedia.org/wiki/Namespace_(computer_science)

Also see

4970 questions
3
votes
2 answers

Assigning std::shared_ptr

In my code, I had ordinary pointer that was dynamically allocated class Texture { //code... SDL_Texture* m_texture; }; I had Init() function from Texture class allocated SDL_Texture*, and destructor released memory. However, this turned out…
MatthewRock
  • 1,071
  • 1
  • 14
  • 30
3
votes
2 answers

Conditionally iterate over some items

I'm iterating some items like this quite a lot in my code: for (; i != end; ++i) { if(!restricted(*i)) { doSomethingWithI(*i) } } Is there a nicer way of doing this, perhaps with std or boost? Another example: for (; i != end; ++i) { …
Baz
  • 12,713
  • 38
  • 145
  • 268
3
votes
1 answer

On namespace 'names': ::std:: vs std::

I have been looking over some posts here on Stackoverflow, and I have noticed that most people use std:: but some people uses ::std:: I think i have read something about a global scope or something like that in namespaces as a reason to use ::std::…
José D.
  • 4,175
  • 7
  • 28
  • 47
3
votes
2 answers

Setting std::vector contents directly using operator []

I notice that if I do vec[0] = 1 with a fresh empty std::vector, vec.size() remains 0. However I can then still do vec[0] to retrieve my 1. Is this in the realm of undefined behavior? What is going on here? Is this simply writing the 1 into…
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
3
votes
1 answer

missing operator= in class

I have the following class, here is it full prototype: class FlowEdge{ private: const uint32_t from_; const uint32_t to_; const double capacity_; double flow_; public: FlowEdge(); FlowEdge(uint32_t from, uint32_t to, double…
karven
  • 65
  • 6
3
votes
3 answers

Destruction of an object when erasing it from std::map

I was curios if default destructor is called, when I'm removing an element from an std::map. Here is an example which I have made: class CTestMap{ public: CTestMap() { std::cout << "default constructor called" << std::endl; } …
JosiP
  • 2,619
  • 5
  • 29
  • 33
3
votes
1 answer

Why is an operator== not sufficient for an std::unordered_map? - C++

Why do I need to implement both the == operator and a random operator returning a size_t? And what should the method returning size_t actually return? EDIT: When I said random operator, I didn't mean it had no use. What I meant is, in my eyes, I do…
Jeroen
  • 15,257
  • 12
  • 59
  • 102
3
votes
4 answers

Why QT's QList methods are made compatible with std::list

What is the reason for having methods such as void QList::push_back ( const T & value ) in QT when it is doing the same thing as append() What kind of compatibly does the documentation means. Can any one please elaborate this Following is the…
Sanyam Goel
  • 2,138
  • 22
  • 40
3
votes
7 answers

std::string getting (char *) instead of (const char *)

std::string.c_str() returns a (const char *) value. I Googled and found that I can do the following: std::string myString = "Hello World"; char *buf = &myString[0]; How is this possible? &myString[0] is an object of type std::string, so how can…
user1365914
  • 858
  • 2
  • 18
  • 32
3
votes
5 answers

sizeof() on C++ Standard Library

I got curious and applied sizeof() operator on some C++ standard Library Classes. Here is what I have observed: int main() { vector v1; set s1; map m1; stack st; queue q; …
banarun
  • 2,305
  • 2
  • 23
  • 40
3
votes
4 answers

Should I avoid using pointers here?

I have this simple code: std::vector> v; //populate v //we know each map already has correct key order (enforced by c++) //but i also want to make sure the different maps have correct key order //this is how I do it using a…
roger.james
  • 1,478
  • 1
  • 11
  • 23
3
votes
3 answers

Calling destructor with decltype and\or std::remove_reference

Is it possible to call destructor(without operator delete) using decltype and\or std::remove_reference? Here's an example: #include #include using namespace std; class Test { public: Test() {} virtual ~Test()…
user1266334
  • 153
  • 2
  • 12
3
votes
2 answers

Trouble in understading behaviour of std::transform

Consider this - #include #include #include #include #include int main() { typedef std::list L; L l(5); typedef L::const_iterator CI; typedef L::iterator I; CI cb = l.begin(), ce…
3
votes
1 answer

Xcode cannot find cstddef

Xcode (iOS) cannot for some reason find cstddef for a library I'm using (Boost). Does any one know how to fix this? I am compiling under Mac OS X 10.8 with Xcode 4.6
James Campbell
  • 3,511
  • 4
  • 33
  • 50
3
votes
1 answer

C++ using namespace declaration

So for a while I've been using... using namespace::std; and recently I realized that's supposed to be using namespace std; Can somebody explain to me why what I was doing worked, and how it differs from the correct way of declaring the usage of a…
kikiotsuka
  • 79
  • 8