General C++ Programming - August 2024

How come a concept receives 2 template parameters but only one is used?
 
How come a concept receives 2 template parameters but only one is used? Here is use of concept Arithmetic in requires clause (2 template parameters) ...
[1 reply] : There are two syntaxes involved, both of which ultimately supply the s... (by DizzyDon)
Parameters and move semantics
 
Here's some error logging code in my program (basically): void SetError(std::string&& arg){ error = arg; } try { // something } catch (st...
[10 replies] Last: I think I've actually got a handle on this now - thank you very much! (by LsDefect)
why pass by universal reference?
 
I understand by universal reference the argument passing following this pattern: template<typename T> void f(T&& t) as in template< class Exe...
[1 reply] : Universal references are useful when you want to move the argument if ... (by Peter87)
Cannot convert from T to T&
 
Cannot convert from T to T& as in the following: auto f(const map<string, int>& mp) { auto p = find_if(mp.begin(),mp.end(), Greater_than{ 42 }); return p; ...
[4 replies] Last: Is there any harm in using auto&&? No, I don't think so. does f re... (by Peter87)
How to write a concept that requires one to create an object to specify that that constructor must exist
 
I need to write the following concept: template<typename T> concept Element = requires (T a, T b) { a = b; T c{ a }; }; I know I can do ...
[no replies]
what are the differences between returning auto, auto&, auto&& and decltype(auto)?
 
what are the differences between returning auto, auto&, auto&& and decltype(auto)? for instance: auto f(int val) { static int value = val; return va...
[1 reply] : For auto and decltype(auto): https://stackoverflow.com/questions/2136... (by George PlusPlus)
Error: Using EigenFFT in for loop
 
I am testing EigenFFT with some Eigen tensors and matrices. I have been so far successful with implementing 1D FFTs along different directions and comparing my ...
[no replies]
what #define are defined
 
Within VS or other, for each source file of a solution/project is there a way of obtaining a list of all #define symbols (including within #include files) and t...
[3 replies] Last: Thanks. I missed that one........ (by seeplus)
are these assignments to temporary valid?
 
Hi, I have this code where I am not sure the assignments are valid: int g(double x) { return std::floor(x); } double& h(double x) { return x; } // return...
[1 reply] : h and i return dangling references. All big compilers (GCC, Clang ... (by Peter87)
vector of unique_ptrs - how to initialize?
 
Hi, I have a vector of std::unique_ptr<Shape> but cannot initialize it. I tried: vector<std::unique_ptr<Shape>> v{ std::unique_ptr<Shape>(new Circle...
[7 replies] Last: std::initializer_list only gives const access to the elements. You c... (by Peter87)
  Archived months: [jul2024]

This is an archived page. To post a new message, go to the current page.