C++ - Reddit
Відкрити в Telegram
Stay up-to-date with everything C++! Content directly fetched from the subreddit just for you. Join our group for discussions : @programminginc Powered by : @r_channels
Показати більше227
Підписники
-124 години
-27 днів
-130 день
Архів дописів
227
I need a fast, forward-iterable data structure that allows objects to be indexed by name
It's a mouthful. I ran into a snag in a game engine I'm writing.
The scenario is this: I have a level editor I'm working on. So far works great. Can drag stuff around. But there is no list of objects in the level yet. To do that, I need at least a forward-iterable list for the UI framework (Qt). The trouble is at least two classes of objects are stored as such:
unordered\_map<string, vector<unique\_ptr<Doodad>>> doodads
Doodads are just a game object. Their function isn't so important here. However, this data structure lets me have two doodads named, say, "statue", one with an index of 0, another with an index of 1. The scripting system can query the engine for how many objects of a particular name exist and access them by "index". This work great for the engine and there are no issues with it whatsoever.
The trouble is this is not so good for the level editor because it is not so easily iterated on as a whole list of objects. At first I started writing a custom iterator. It looks messy.
doodad_iterator& doodad_iterator::operator++()
{
list_iter++;
if (list_iter == map_iter->second.end())
{
map_iter++;
if (map_iter == map.end())
{
go_end();
}
else
{
list_iter = map_iter->second.begin();
}
}
return *this;
}
void doodad_iterator::go_end()
{
map_iter = map.end();
list_iter = map.begin()->second.begin(); // ignore for now that this would crash if it's empty
}
Then I thought about writing a class that reads the entire list and stores all the current doodads in a vector. Easily iterable, but needs updating every time you add or remove one.
Then I started writing a class which would store the objects in a vector of vectors, and the names would be handled using a map that points to one of the other lists.
template<class T>
class indexable_list
{
using pointer = T*;
using list = std::vector<std::unique_ptr<pointer>>;
using index_map = std::unordered_map<std::string, *list>;
using object_store = std::vector<list>;
object_store objects;
index_map map;
};
Although the object pointers are stored contiguously, it falls apart once you remember resizing a vector would start invalidating pointers.
I'm drawing a blank on alternatives that would store pointers contiguously.
At the very least, I need:
* Iterate on objects forward/backward
* Keep the current setup of indexing objects by name
* Allow random access (a bonus, not needed)
* Not affect the performance of the engine in name lookup, creation and deletion
* It also needs size() (for the UI framework)
If nothing else, I may go with the custom iterator above, do something else for reaching the end, and create a templated class around it so I can create name\_indexed\_list or something.
https://redd.it/mhpak5
@r_cpp
227
C++ Production Debugging with bpftrace and uprobes
https://tenzir.com/blog/production-debugging-bpftrace-uprobes/
https://redd.it/mhpzjd
@r_cpp
227
C++23: -> and :: to be replaced by . operator
https://codingtidbit.com/2021/04/01/c23-and-to-be-replaced-by-operator/
https://redd.it/mhps1q
@r_cpp
227
vcpkg Host Dependencies for Cross-Compilation | C++ Team Blog
https://devblogs.microsoft.com/cppblog/vcpkg-host-dependencies/
https://redd.it/mhou6a
@r_cpp
227
A great youtube channel for c++ biggeners. Please subscribe this
https://youtu.be/SYRBbW0DaZw
https://redd.it/mhnr2g
@r_cpp
227
Which gui library does device monitoring studio developed with?
The website: https://www.hhdsoftware.com/device-monitoring-studio
​
Thank you.
https://redd.it/mhlhjl
@r_cpp
227
jvpatterns - proof-of-concept for pattern matching
Hello,
I have produced a proof-of-concept for composable and customizable pattern matching as a C++17 template library.
With it, I managed to make a HTTP message parser in a hundred lines of code.
I have written a small article to demonstrate its use: https://www.jvernay.fr//en/libs/jvpatterns.html
What do you think? Do you have some specific use cases where it could be handy? Or some neat features which cannot be done currently?
Any feedback appreciated :)
https://redd.it/mh8fkc
@r_cpp
227
Implementing Generators with C++20 Coroutines
https://www.youtube.com/watch?v=D0snE2-BOwM
https://redd.it/mheg8f
@r_cpp
227
C++ coroutines: The initial and final suspend, and improving our return_value method
https://devblogs.microsoft.com/oldnewthing/20210331-00/?p=105028
https://redd.it/mh7dru
@r_cpp
227
Discrete-event simulation in C++20 using coroutines
https://github.com/fschuetz04/simcpp20
https://redd.it/mh4mwi
@r_cpp
227
Will we ever get rid of macros in C++?
Except conditional compilation, is there any reason that we still use macros in C++ programming?
https://redd.it/mgwfm8
@r_cpp
227
Is it a mistake that C++ modules have no notion of versioning?
Say, a C++ programmer imports a module "A" in his program, while another programmer imports the same module but requiring a different version of module A. But C++ modules don't support module versioning. So, there is no way that a programmer expresses his intention as "importing module A version X". This seems unnecessarily restrictive. Why not make C++ modules support module versioning from the start, so that each building system does not have to invent its own way to do it?
https://redd.it/mgwwpl
@r_cpp
227
C++ course in Udemy: 200+ video courses
C++ course in Udemy: 200+ video courses, exercises, and more!
https://redd.it/mgptup
@r_cpp
227
Ann: CPP Companion to learning Digital Signal Processing
In the tradition of ThinkDSP by Prof Downey, a C++ layer has been developed utilizing GNU Scientific Library for implementation. Strictly for pedagogic purposes:
https://github.com/RajaSrinivasan/assignments/blob/master/dsp.pdf
and
https://gitlab.com/cpp8/thinkdsp.git
Hoping it is of use to the community. Contributions and participation in continued development welcome.
Best, Srini
https://redd.it/mgdl5g
@r_cpp
227
Introduction to memory allocators and arenas
https://muit.github.io/posts/2021/03/introduction-to-allocators-and-arenas/
https://redd.it/mglr1e
@r_cpp
227
C++ coroutines: Basic implementation of a promise type
https://devblogs.microsoft.com/oldnewthing/20210330-00/?p=105019
https://redd.it/mgjpa8
@r_cpp
227
C++ coroutines: The mental model for coroutine promises
https://devblogs.microsoft.com/oldnewthing/20210329-00/?p=105015
https://redd.it/mfqztq
@r_cpp
227
Is C++ superior to Rust in any way from a purely technical standpoint?
Currently learning C++ effectively as a newcomer. I'm aware of the much better job opportunities and extensive library support and ecosystem compared to Rust, which generally means C++ is often the only contender for any serious application development, or dealing with existing codebases etc.
Hypothetically, assuming a new project with identical library support for the task, I'm wondering if there's any reason a lone developer/team of developers who are equally skilled in both C++ and Rust would code a project in C++. A lot of people who like Rust say that programming in C++ is something they really don't like after using Rust, and on paper they seem to be right.
https://redd.it/mfoywv
@r_cpp
Вже доступно! Дослідження Telegram за 2025 — головні інсайти року 
