stl Questions

6

Solved

The implementation of these methods seems straightforward to me and they would make usage of std::string and std::string_view more interchangeable. After all, std::string_view has constructors whic...
Carloscarlota asked 24/1, 2019 at 11:53

8

Solved

I have a set of data which is split into two arrays (let's call them data and keys). That is, for any given item with an index i, I can access the data for that item with data[i] and the key for th...
Treed asked 3/8, 2010 at 16:57

3

cppreference states: The ranges library is an extension and generalization of the algorithms and iterator libraries that makes them more powerful by making them composable and less error-prone. ...
Dittany asked 10/3, 2023 at 10:21

2

Solved

I'm new to c++ and I'm learning about vector. I wrote a basic code to see how it works but i get the following errors. ||=== Build file: "no target" in "no project" (compiler: unknown) ===| C:\Use...
Millepede asked 9/6, 2017 at 10:39

7

Solved

I want to erase some elements in my std::map. I wrote erase + remove_if technique which I always do with other sequence containers. But it wasn't compile with map. Why? And How can I do this job? ...
Vennieveno asked 10/8, 2011 at 8:23

6

Solved

If I have the following vector {10 10 10 20 20 20 30 30} and I want a function to return the position of the integer that = X or directly the smaller element after X , like for example if I am sear...
Titos asked 15/11, 2012 at 14:11

7

Solved

I am learning STL and design patterns . i wanted to know is there any document or link that explains how design patterns are implemented in STL i did the google but not able to get much data ...
Amaryllidaceous asked 23/4, 2010 at 12:34

8

Solved

I have a map in a multithreaded app mapping a class called uuid to pointer. What I want to know if an insert operation succeeded for failed. e.g. _mymap.insert(hint, MyMap::value_type(entry.uuid,...
Christadelphian asked 24/2, 2011 at 14:46

3

Solved

In C++20, there are two swap function templates: std::ranges::swap(T&&, U&&) and std::swap(T&, T&). I just wonder: What's the difference between they two?
Markson asked 25/7, 2021 at 7:42

6

Solved

I need to find how many elements are lower than a given one in a std::set. I thought the right function to use was std::lower_bound which returns an iterator to the first element which is greater ...
Dillingham asked 9/3, 2016 at 14:22

5

Solved

I study data structures and I want to ask what are the equivalents of STL containers. for example vector = dynamic array queue = queue stack = stack priority_queue = heap list = linked list set ...
Unclasp asked 16/6, 2012 at 15:14

7

There is an associated container in C++ which is actually a set (multiset) which can give the order of an element in it in. Here is how I use the container: #include <bits/stdc++.h> #includ...
Joubert asked 14/1, 2020 at 10:30

10

Solved

I would like to write a template that will determine if a type is an stl container at compile time.   I've got the following bit of code: struct is_cont{}; struct not_cont{}; template ...
Rubbery asked 23/2, 2012 at 4:51

6

Solved

I have a question on how pointers to a custom object are handled when used as Keys in an map. More specifically if I define std::map< CustomClass*, int > foo; Would the default C++ implem...
Recalcitrate asked 4/8, 2014 at 16:6

3

Solved

What is the difference in getting a value through aMap[key] and aMap.at(key) in C++?
Mystic asked 30/5, 2012 at 17:38

3

Solved

I've been happily using the following style of constant string literals in my code for awhile, without really understanding how it works: constexpr std::array myStrings = { "one", "t...
Laurasia asked 15/4, 2022 at 10:11

1

The proposal for shared_ptr<T[N]> has this paragraph: https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3920.html The unfortunate occurence of unique_ptr having lost its support for ...
Unquestioned asked 24/5 at 0:41

2

Solved

In my code I have a std::unordered_set and I need to move the data into a std::vector. I'm using the std::unordered_set while getting the data to ensure only unique values are stored prior to conve...
Hewitt asked 28/2, 2017 at 22:24

5

Solved

Let's say that I've got a : #include <utility> using namespace std; typedef pair<int, int> my_pair; how do I initialize a const my_pair ?
Doralynn asked 5/8, 2009 at 8:5

3

Solved

I read an answer here showing how to read an entire stream into a std::string with the following one (two) liner: std::istreambuf_iterator<char> eos; std::string s(std::istreambuf_iterator&...
Mutt asked 27/10, 2014 at 14:3

2

Solved

I want to loop through a vector in a sorted way without modifying the underlying vector. Can std::views and/or std::range be used for this purpose? I've successfully implemented filtering using vie...
Irrepressible asked 4/3, 2022 at 8:41

2

Solved

I have two std::map<> objects a and b and would like to move (extract + insert) some elements (nodes) from one map to the other based on some predicate p. for (auto i = a.begin(); i != a.end...
Nonsense asked 13/11, 2019 at 14:24

1

Solved

I just noticed that std::map and std::set have the member function equal_range() returning an iterator range of values for a certain key. How does this make sense when std::map and std::set a...
Garwin asked 1/5 at 8:36

11

Solved

Since they are both contiguous memory containers; feature wise, deque has almost everything vector has but more, since it is more efficient to insert in the front. Why whould anyone prefer std:...
Sledge asked 17/3, 2011 at 20:57

3

Solved

I'm using external networking library which returns some magic structures representing opened sockets and the docs say that when inserting them into STL containers, they should be compared using st...
Floodgate asked 13/7, 2015 at 7:58

© 2022 - 2024 — McMap. All rights reserved.