Skip to main content
2 votes
2 answers
141 views

I'm trying to do something like this: const std::map<char, int> histogram{ {'A', 2}, {'D', 1}, {'M', 1}, }; for (const auto& [index, key, value] : std::views::enumerate(...
Adam Badura's user avatar
  • 5,533
6 votes
1 answer
347 views

I'm experimenting with the new C++ compile-time reflection features (as described in P2996R0) and I testing a simple enum_to_string() utility using template for: template <typename E> requires ...
Artem Selivanov's user avatar
0 votes
3 answers
93 views

I've read that to make one's custom container work with range-based for loop, "things" need to be in the same namespace. What things need to be in same namespace? The begin-end free ...
Newline's user avatar
  • 983
2 votes
1 answer
146 views

I want to modify (push_back) element while iterate vector like this: auto main() -> int { std::vector<double> v { 1, 2, 3 }; for (auto& num : v) { std::cout << num &...
Fei Yu's user avatar
  • 65
2 votes
2 answers
109 views

I use to parse lines from a file by writing, ifstream input(filename); for (string line; getline(input, line); /**/) do_something_with(line); ... but is it possible to elegantly (or with some boost ...
Darko Veberic's user avatar
1 vote
1 answer
201 views

Hi I have a quick question - over here it says ranged-based for loops of the form for ( init-statement (optional) range-declaration : range-expression ) are equivalent to the code: { auto &&...
riverofwind's user avatar
0 votes
1 answer
128 views

I want to loop over a vector of objects each containing another vector of objects to be looped over in turn. The subvector/contained vector object members need to be able to be able to be modified and ...
riverofwind's user avatar
0 votes
2 answers
173 views

I'm confused with range of enums. I have code like this: namespace regs { enum Control_0 { THING1, THING2, THING3 }; enum Control_1 { THING100, THING200, THING300 }; const auto ...
eklund's user avatar
  • 3
3 votes
1 answer
136 views

In range-based for when begin-expr and end-expr are begin(range) and end(range), the names begin and end are not looked up using ordinary lookup. Just ADL is performed. See C++23 [stmt.ranged]#1.3.3. ...
Dr. Gut's user avatar
  • 3,335
3 votes
2 answers
874 views

I need to check data of a std::map, and remove some of them. I'm using a range-based "for" loop, like this: std::map<int, string> data { { 1, "name1" }, { 2, "name2"...
Leon's user avatar
  • 2,165
3 votes
2 answers
231 views

I want to have the following work std::vector<int> range{0,1,2,3}; for(std::vector<int>::iterator vit : range | iterator_range ){ int v = *vit; } this would be equivalent to the ...
bradgonesurfing's user avatar
0 votes
0 answers
45 views

**The code I tried to implement is : ** #include<iostream> using namespace std; int main() { int n, k; cout << "Enter the number of elements: \n"; cin >> n; ...
Abhinav's user avatar
  • 19
0 votes
1 answer
117 views

In the following code, we cannot iterate over set s1 using non-const reference. Why? #include <set> struct st { unsigned int f; std::set<int> s2; }; struct comp { bool operator()(...
Ali Tavakol's user avatar
0 votes
2 answers
125 views

I was trying out some C++20 when I stumbled upon a rather strange (at least to me) situation. I was expecting the following code to not work with one of my examples (I've specified the expected ...
Emiliano Toledo's user avatar
-2 votes
1 answer
327 views

I feel like this should have an answer already but I wasn't able to find it. I have a vector of shared_ptrs: vector<shared_ptr<X>> v; I don't want to do anything with ownership (e.g. ...
NPS's user avatar
  • 6,424

15 30 50 per page
1
2 3 4 5 6