• Forum
  • General C++ Programming

General C++ Programming

by admin
Welcome to this board!
 
Welcome to the general programming forum in C++.com! In this forum, users can to talk about any topic related to programming in the C++ language that does not ...
[no replies]
by Zaap
vector push_back passing size from 0 to overflow
 
Hi, please see the following code and the associated prints. I also add the Argument class below. Basically, it crashes the second time it goes in the loop b...
[3 replies] Last: Bumping this to just give some insight that might be generally helpful... (by Ganado)
The object itself (this) is it a leak if its constructor throws?
 
if the ctor throws, then the object this has already received the memory (some new or alloc has been executed)... so, does the object this leak? the only possi...
[7 replies] Last: Excellent comments! Thank you again!! (by JUANDENT)
Convert MATLAB function to C++
 
I have a function from a textbook: https://people.maths.ox.ac.uk/trefethen/spectral.html Basically it calculates the Chebyshev differentiation matrix and I hav...
[14 replies] Last: @mbozzi I think the problem is that duyk is too small to hold the en... (by JamieAl)
by Zaap
Threading: changing processor count does not change performances
 
Hi, I've been doing some multi-threading in my program. This program essentially iterates over a dataset and for each line computes some stuff. My multi-t...
[8 replies] Last: [quote=Zaap]I think using a for_each in my code will create an excessi... (by TheIdeasMan)
Why is my fft function not working as expected?
 
Trying to take the fft of 2D array along one direction (x for example and not y) so it's a 1D FFT of 2D array. I have done this successfully before using Eigen ...
[9 replies] Last: it makes no difference whether you store your matrix row or column maj... (by jonnin)
Cyclic dependencies - how to deal with them?
 
Hi, I have a class GridCtrl that delegates to GridCtrlHandler but GridCtrlHandler must also be able to call methods on GridCtrl. I cannot have GridCtrl.h ...
[6 replies] Last: Heh, I created a circular dependency issue using modules and Visual St... (by George P)
why use decltype(auto) return type instead of auto?
 
Hi, I have this code namespace detail { template <class F, class Tuple, std::size_t... I> decltype(auto) apply_impl(F&& f, Tuple&& t, std::index_sequence<I....
[3 replies] Last: I swear modern C++ is a minefield Too bad there's no golden idol acr... (by George P)
by Cplusc
MPI Blocking and Non_Blocking Communication
 
I'm currently working on a lattice Boltzmann code (D3Q27) employing MPI for parallelization. I've implemented MPI 3D topology for communication, and my code sni...
[7 replies] Last: @mbozzi thanks for your help. In your algorithm, I assume there's a ... (by Cplusc)
C++23 Formatting Ranges
 
C++23 added the ability to "print out" using formatting options a container directly instead of having to use some form of a loop to access each element individ...
[no replies]
How to convert local_time to sys_time?
 
Hi, I have this local time_point: auto loc = std::chrono::current_zone()->to_local(std::chrono::system_clock::now()); and need to change it to sy...
[2 replies] Last: thanks!! (by JUANDENT)
friend and enable_if in operator%
 
This code is not compiling: template<typename T> class Number { T value; public: [ ] explicit Number(const T& t) : value(t) { } templa...
[3 replies] Last: Heh, well, ye learn something new every day. (I’m still using C++17 ... (by Duthomhas)
by Cplusc
DFS and DLS Algorithm
 
I am supposed to write a C++ code to answer the following questions but before that I need to be able to answer the questions on paper to write the correct code...
[14 replies] Last: Heh, glad I’ve been of use to you. :O) A large part of my degree wa... (by Duthomhas)
what is the epoch of pseudo-clock local_t?
 
I created an empty time point that represents epoch time: auto tse = chr::time_point<chrono::local_t, chrono::duration<int, ratio<1, 1>>>{}; what da...
[2 replies] Last: Internally, tse stores a duration since the Unix epoch. https://st... (by mbozzi)
by Cplusc
BSF Algorithm
 
An undirected graph has 24 vertices denoted by A’, B,’ C’, D’, E’, F’, G’, H’, I’, J’, K’, L’, M’, N’, P’, Q’, R’, S’, T’,...
[2 replies] Last: @Keskiverto Thanks for the answer. (by Cplusc)
Can you give me an example of parametric polymorphism
 
Hi, I need a few examples of parametric polymorphism please. Regards, Juan Dent
[1 reply] : Here's what CoPilot has to say: Certainly! In C++, parametric polymo... (by AbstractionAnon)
why does this lambda expression not work
 
following the book C++ Template Metaprogramming I find the following lambda expression that does not do what it's supposed to: using argument_types = mpl:...
[2 replies] Last: Thanks!! That's it! (by JUANDENT)
operator<=> implementation is correct?
 
Hi, It is not clear to me how to implement the <=> operator. As an example let's look at a type: struct Integer { int i; long j; explicit Inte...
[3 replies] Last: Have a look at: https://www.modernescpp.com/index.php/the-autogenerate... (by seeplus)
boolean test
 
For bool b, is the test if (b) slightly faster than if (!b)? For example, should I change code if (!b) do_a(); else do_b(); into if (b) do_b(); else...
[8 replies] Last: I don't think we can say in general which is "faster". If there is an... (by mbozzi)
How to get std::priority_queue to update dynamically when element priorities change?
 
Suppose you have a custom type, Foo , whose Num member is used to determine priority in a priority_queue: struct Foo { string Name = ""; int...
[4 replies] Last: what you are talking about is a sorted container that is smart enough ... (by jonnin)
  Archived months: [jan2024]