Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
-4 votes
0 answers
64 views

how often do you use the noexcept or constexpr modifier [closed]

how often do you use the noexcept or constexpr modifier in real work? Scott Myers wrote a lot about the importance of these structures, but why in practice I rarely saw this with my colleagues, share ...
-4 votes
0 answers
89 views

Which C++ string type should I migrate to? [closed]

I see so many options for C++ string types, like: std::string std::u16string std::u8string CString Platform::String wchar_t char Narrowing this down a bit, my 3 options seem to be: std::string - ...
user2912647's user avatar
-1 votes
1 answer
55 views

External Data Structure Used in Custom Comparison Function in C++ [duplicate]

I have array of numbers and I have to sort them based on there frequency in ascending order and if both numbers are same then sort them in decreasing order what I did was I create unordered_map and ...
BhavyaMPatel's user avatar
1 vote
3 answers
128 views

Behaviour of std::is_sorted function in C++

Consider the following C++ program which checks whether the given array is sorted or not. #include <iostream> #include <vector> #include <algorithm> int main() { std::vector<...
Soo's user avatar
  • 999
-3 votes
1 answer
71 views

count the maximum number of triangles made up of a sequence of numbers Two triangles are called the same if they have 3 pairs of sides equally [closed]

WE HAVE A ARRAY: 2 3 3 4 4 4 6 6 6 6 Maximum number of triangles formed: 12 BECAUSE: (4, 4, 4) 4) (4, 4, 2) (4, 4, 3) (4, 4, 6) (6, 6, 2) (6, 6, 3) (6, 6, 4) (2, 3, 4) (3, 4, 6) (6, 6, 6) (3, 3, 2) (3,...
Đăng Quang Hồ's user avatar
-1 votes
0 answers
97 views

why std::move(std::vector<int>) does not move [duplicate]

I'm really confused cause of C++ having so many "unspecified states". In the code below, I'm trying to move std::vector to a set(&&) function, but the output seems like it's not ...
rishi's user avatar
  • 731
-1 votes
2 answers
56 views

C++ Rectangle 2D Array with numbers beside the rectangle

I've been trying to make a 2D array of rectangle, and i want the number of index x to printed beside the rectangle and index y to be printed below the rectangle.. Here is my code.. int height, width; ...
ken's user avatar
  • 1
-2 votes
0 answers
75 views

Undefined reference to std::string while linking, but the header doesn't seem to be the problem [duplicate]

I am translating a program that was written in C to C++. It was as easy as changing the suffix to the file and modifying some compiler flags. Before using actual C++ features, it compiled perfectly. ...
Bestemmie's user avatar
1 vote
1 answer
118 views

Two almost similar multithreaded code have very different running time

i am having a strange problem for C++ multithreaded programs. i wrote the first code and was not seeing any performance improvement over single threaded code. i kept on experimenting with shifting the ...
programmer of c's user avatar
1 vote
2 answers
109 views

Why exception can not be caught on windows by msvc but on Linux by GCC [duplicate]

The same files on Windows and Linux as follow: std_exp.cpp #include <iostream> #include <string> #include <stdexcept> using namespace std; int main() { try { std::...
Monhde Sau Hung's user avatar
-3 votes
1 answer
71 views

Understanding usage of std::for_each with structs [duplicate]

I am trying to understand how below code works, from cpp reference website: std::vector<int> v{3, -4, 2, -8, 15, 267}; struct Sum { void operator()(int n) { sum += n; } int sum {0}; }; ...
barribow's user avatar
  • 111
0 votes
0 answers
61 views

Templating CUDA

CUDA supports templates and that is nice, I have however problem with interplay with C++. Let's say I have functions template <typename T> void CUDAZeroPad2D(dim3 threads, ...
VojtaK's user avatar
  • 610
0 votes
0 answers
61 views

Right memory_order to react on atomic increment changes in other thread?

Consider such code: #include <atomic> #include <thread> bool read_from_network() noexcept; void write_to_network() noexcept; int main() { std::atomic<size_t> work_counter; std:...
user1244932's user avatar
  • 7,932
0 votes
1 answer
63 views

Guarding tests against exit/death

I'm using googletest to test multi-threading code with std::thread. In broken code, it often happens that a std::thread is destroyed before the thread has joined, causing a program termination. ...
Hendrik's user avatar
  • 567
4 votes
2 answers
118 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

15 30 50 per page
1
2 3 4 5
3268