« first day (2765 days earlier)      last day (312 days later) » 

00:21
Hi all! Does anyone know off the top of their heads how to check equality of a multi-word pre-compiler macro? For instance,

#define x long double

// elsewhere...
#if (x == long double)
do something
#endif

The above code won't compile in GNU `g++`, reporting `error: missing binary operator before token "double"`. Any ideas?
 
3 hours later…
03:28
@AntiEarth many ways: en.cppreference.com/w/cpp/types/is_same although not clear what you're doing
 
4 hours later…
07:48
huh, I never thought about how the regular constructor of Base will get called with one vtable, but when a Derived gets copied the copy constructor would potentially get called with a different vtable.
Should rarely be an issue, just another fantastic little corner for surprising behavior to hide in.
 
5 hours later…
13:12
@Mikhail I need to check a pre-compiler macro. How can I use std::is_same here? I forgot to mention it must also be C-compatible, and this occurs entirely in a header
13:51
Hi everyone, quick question: I have a std::vector<mapNode> of a custom data type called mapNode. I want to be able to search in this entire vector if mapNode.nodeId == "someString", and delete the structure in that particular index. What would be the STL way of achieving this?
I am currently iterating through the vector, and searching for the particular field in each element. Then I store the index, and once I have searched the entire vector, then I use the index to delete the particular entry. This seems like a long process to me
do you need the vector to remain in order? if not then you can swap with the back element and pop_back, that saves you one O(n) operation on the remove
and a linear search isn't that horrid when the vector is small
 
2 hours later…
15:54
@ssarkar it's just std::erase_if(v, [](const mapNode& m){return m.nodeId == "some String";});
if you don't have C++20 it's this instead:
auto it = std::remove_if(v.begin(), v.end(), [](const mapNode& m){return m.nodeId == "some String";});
v.erase(it, c.end());
 
4 hours later…
19:54
10 messages moved from Lounge<C++>

« first day (2765 days earlier)      last day (312 days later) »