Skip to main content

Questions tagged [std]

The C++ Standard Library, and its namespace. Use it in conjunction with: [c++], [c++11], [c++14], [c++17], [c++20], [c++23].

0 votes
1 answer
38 views

Design a Data Structure for Efficient Key-Value Operations with Top K Check in c++

Data Structure Requirements Design a data structure that supports the following operations: Insertion: Insert a key-value pair. Deletion: Delete a key-value pair. Check Top K: Given an integer k and ...
דיני נ's user avatar
0 votes
0 answers
66 views

std::unordered_set with memory location control?

I would like to have a data structure that stores items of some type 'Key' but additionally provides an access to the memory location where it is stored. More specifically, consider the following ...
cppuser's user avatar
  • 11
2 votes
1 answer
96 views

In C++ std::ranges, how do I build a map out of a views::join result?

I'm using GCC 14 in C+23 mode. In the following code, I create a view of views of pairs, which I then flatten with views::join and put into a vector: auto c = std::ranges::views::iota(1, 5) | ...
notsurewhattodo's user avatar
-4 votes
0 answers
55 views

Unusual Access Violation when joining a thread [closed]

When terminating my program, the many components join their threads and this particular one gives me an access violation when joined along with other components at the same time. The code is simple - ...
SagunKho's user avatar
  • 1,011
7 votes
2 answers
139 views

Does it make any sense to define operator< as noexcept?

I know that it makes perfect sense to define e.g. move constructor as noexcept (if possible) and I think I understand the effect of that. But I have never seen a similar discussion about operator<()...
Jarek C's user avatar
  • 1,237
-2 votes
0 answers
46 views

Replacing direct usage of std::_Dist_type from old msvc100 code for msvc142

I'm working on upgrading some old c++ code from msvc100 to msvc142. My problem is I am not a C++ developer, but come from C#, and I'm running into a problem with a specific type that was used directly ...
Capsup's user avatar
  • 83
4 votes
2 answers
116 views

Idiomatic ways of using tuples and std::tie

I am trying to implement the modular multiplicative inverse using the extended Euclidean algorithm in C++. In Python, the code for this is concise and idiomatic, using tuple unpacking: def inv_modulo(...
João Areias's user avatar
  • 1,338
-1 votes
0 answers
62 views

Initializing vector and array with initializing list of objects that only have move constructor [duplicate]

For the following class with only move constructor: class Foo { public: Foo(const Foo& foo) = delete; Foo(Foo&& foo) = default; Foo() = default; }; Why would initializing a ...
ttzytt's user avatar
  • 79
5 votes
2 answers
114 views

Is it undefined behavior to directly remove elements from the underlying range of filter_view?

For the following code: void foo(std::set<int>& s) { for (int val : s | std::views::filter([](int i) { return i > 0; })) { s.erase(val - 3); } } This code is not intended ...
Pluto's user avatar
  • 1,032
1 vote
1 answer
98 views

Constructor with initializer list for std::map

Following the advice of not extending std containers from this question , I am creating my own type and using std::map as a class attribute. I am re-creating the public interface functions I want from ...
Mickaël C. Guimarães's user avatar
0 votes
2 answers
156 views

C++ vector: for loop to std::transform [duplicate]

I got a code in the following form vector<int> vec{ 1,2,3 }; vector<int> vec2{ 4, 5, 6, 7, 8, 9 }; for (int i = 0; i < vec2.size(); i++) { if (vec2[i] % 2 == 0) vec....
RocketSearcher's user avatar
5 votes
1 answer
142 views

Why does take(n) used on an istream_view cause it to skip the next token in C++20?

In C++20, when I use std::ranges::views::take() on a std::ranges::istream_view(), the next token in the istream_view after iterating the take view is skipped. Consider the following C++20 code snippet:...
ashpool's user avatar
  • 243
-2 votes
0 answers
77 views

std::thread raise STATUS_STACK_BUFFER_OVERRUN

Consider the following code: #include <iostream> #include <thread> #include <functional> using namespace std; class CThreadHandler { public: void Start() { m_thread ...
Ouroboros72's user avatar
3 votes
1 answer
124 views

Is Insertion into a vector while also accessing a vector undefined behavior?

Just stumbled upon a post that talked about reference and iterator invalidation on insertion into a vector. But will accessing a vector by index also result in undefined behavior? Is the below code ...
theCuriousOne's user avatar
1 vote
0 answers
53 views

compiler finds both std::to_address and cuda::std::to_address

I'm trying to build the Nvidia's Minkowski Engine, so I did the following: git clone https://github.com/NVIDIA/MinkowskiEngine.git cd MinkowskiEngine python setup.py install However, I get this ...
Megapiot's user avatar

15 30 50 per page
1
2 3 4 5
407