r_cpp | Unsorted

Telegram-канал r_cpp - C++ - Reddit

-

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

Subscribe to a channel

C++ - Reddit

Is there any good sources for Digit Dp and Dp on Trees??

I need to do these topics but I cannot find a good source.

https://redd.it/1m0rnrq
@r_cpp

Читать полностью…

C++ - Reddit

Latest News From Upcoming C++ Conferences (2025-07-15)

This Reddit post will now be a roundup of any **new** news from upcoming conferences with then the full list being available at [https://programmingarchive.com/upcoming-conference-news/](https://programmingarchive.com/upcoming-conference-news/)

**EARLY ACCESS TO YOUTUBE VIDEOS**

The following conferences are offering Early Access to their YouTube videos:

* **ACCU Early Access Now Open (£35 per year) -** Access all 91 YouTube videos from the 2025 Conference through the Early Access Program. In addition, gain additional benefits such as the journals, and a discount to the yearly conference by joining ACCU today. Find out more about the membership including how to join at [https://www.accu.org/menu-overviews/membership/](https://www.accu.org/menu-overviews/membership/)
* Anyone who attended the ACCU 2025 Conference who is NOT already a member will be able to claim free digital membership.

**OPEN CALL FOR SPEAKERS**

The following conference have open Call For Speakers:

* **C++ Day** \- Interested speakers have until **August 25th** to submit their talks. Find out more including how to submit your proposal at [https://italiancpp.github.io/cppday25/#csf-form](https://italiancpp.github.io/cppday25/#csf-form)

**OTHER OPEN CALLS**

* **ADC Call For Talk Reviewers Now Open** \- Anyone interested in reviewing talk proposals for ADC 2025 can now review talks at [https://submit.audio.dev](https://submit.audio.dev)
* **ADC Call For Online Volunteers Now Open** \- Anyone interested in volunteering online for ADCx Gather on Friday September 26th and ADC 2025 on Monday 10th - Wednesday 12th November have until September 7th to apply. Find out more here [https://docs.google.com/forms/d/e/1FAIpQLScpH\_FVB-TTNFdbQf4m8CGqQHrP8NWuvCEZjvYRr4Vw20c3wg/viewform?usp=dialog](https://docs.google.com/forms/d/e/1FAIpQLScpH_FVB-TTNFdbQf4m8CGqQHrP8NWuvCEZjvYRr4Vw20c3wg/viewform?usp=dialog)
* **CppCon Call For Volunteers Now Open** \- Anyone interested in volunteering at CppNorth have until August 1st to apply. Find out more including how to apply at [https://cppcon.org/cfv2025/](https://cppcon.org/cfv2025/)

**TICKETS AVAILABLE TO PURCHASE**

The following conferences currently have tickets available to purchase

* **Meeting C++** \- You can buy online or in-person tickets at [https://meetingcpp.com/2025/](https://meetingcpp.com/2025/)
* **CppCon** \- You can buy regular tickets to attend CppCon 2025 in-person at Aurora, Colorado at [https://cppcon.org/registration/](https://cppcon.org/registration/).
* **ADC** \- You can now buy early bird tickets to attend ADC 2025 online or in-person at Bristol, UK at [https://audio.dev/tickets/](https://audio.dev/tickets/). Early bird pricing for in-person tickets will end on September 15th.
* **C++ Under The Sea** \- You can now buy early bird in-person tickets to attend C++ Under The Sea 2025 at Breda, Netherlands at [https://store.ticketing.cm.com/cppunderthesea2025/step/4f730cc9-df6a-4a7e-b9fe-f94cfdf8e0cc](https://store.ticketing.cm.com/cppunderthesea2025/step/4f730cc9-df6a-4a7e-b9fe-f94cfdf8e0cc)
* **CppNorth** \- Regular ticket to attend CppNorth in-person at Toronto, Canada can be purchased at [https://store.cppnorth.ca/](https://store.cppnorth.ca/)

**OTHER NEWS**

* **Last Chance to Buy CppNorth Tickets** \- CppNorth starts on Sunday 20th July in Toronto, Canada. Buy a ticket today at [https://store.cppnorth.ca/](https://store.cppnorth.ca/)
* **Provisional Meeting C++ Schedule Now Available** \- More information about the schedule can be found at [https://meetingcpp.com/meetingcpp/news/items/The-end-of-ealry-bird-tickets-and-a-first-schedule.html](https://meetingcpp.com/meetingcpp/news/items/The-end-of-ealry-bird-tickets-and-a-first-schedule.html)

Finally anyone who is coming to a conference in the UK such as ADC from overseas **may now be required to obtain Visas to attend**. Find out more including how to get a VISA at

Читать полностью…

C++ - Reddit

Need some guidance on low latency programming is it worth pursuing?

Hey folks,

I'm an undergrad entering my final year. My background so far has mainly been around web development and general SDE work. Recently, I joined a fintech startup as an intern, and they assigned me to work on their backtesting module originally written in Python which I then converted to C++.

I managed to get ~5x speedup compared to the Python version, mostly by using basic stuff like unordered_map and a simple DP-style cache. But honestly, I know this is nowhere near what C++ is really capable of in terms of performance and low-level optimization.

Now, as placement season approaches, I’m in a dilemma. Should I continue on the typical SDE path, or should I dive deep into low-latency programming or some niche like that? The problem is I come from a college that HFTs in India don’t hire from (they mostly recruit from 2-3 top-tier colleges, mine’s not even close), and ironically, I’m not getting shortlisted for SDE roles either.

So I wanted to ask:

What kind of roles and opportunities does low latency programming actually open up?

Is it just HFTs, or are there other paths as well?

And if it is worth it for someone in my position, what should be my starting point? What should I learn, practice, or build?


Sorry if this doesn’t belong here just trying to figure out my direction and would really appreciate any insights.

Thanks!


https://redd.it/1m0j22j
@r_cpp

Читать полностью…

C++ - Reddit

Dot product on misaligned data
https://lemire.me/blog/2025/07/14/dot-product-on-misaligned-data/

https://redd.it/1m0clws
@r_cpp

Читать полностью…

C++ - Reddit

There is a std::chrono::high_resolution_clock, but no low_resolution_clock
https://devblogs.microsoft.com/oldnewthing/20250714-00/?p=111375

https://redd.it/1m099la
@r_cpp

Читать полностью…

C++ - Reddit

Preparing for C++/C# roles at trading firms what should I focus on over the next 2 years?

Hi everyone,

I’m a recent CS graduate who just started a job working with C# and C++. My long-term goal is to work at a trading firm on a C++/C# development team.

I’m aiming to apply in about 2 years, once I’ve built up enough experience and skills to be a competitive candidate. I’d really appreciate any guidance on:
1. What skills/knowledge should I focus on over the next 2 years to prepare for interviews at trading firms?
• Systems programming? Leetcode-style DSA? Networking? Multithreading?
• Are there specific books, projects, or open-source contributions that help?
2. Do trading firms hire people with just 2 years of experience, or do they mainly target new grads and senior/experienced hires?
3. What is the interview process like for someone with 1–3 years of experience?
• Is it mostly Leetcode questions, or more focused on systems design, low-latency coding, etc.?

https://redd.it/1m041dh
@r_cpp

Читать полностью…

C++ - Reddit

The Best C++ Library
https://mcyoung.xyz/2025/07/14/best/

https://redd.it/1lzyeyc
@r_cpp

Читать полностью…

C++ - Reddit

Spicy: Generating Robust Parsers for Protocols & File Formats
https://docs.zeek.org/projects/spicy/en/latest/index.html

https://redd.it/1lzxme7
@r_cpp

Читать полностью…

C++ - Reddit

New C++ Conference Videos Released This Month - July 2025 (Updated to Include Videos Released 2025-07-07 - 2025-07-13)

**C++Online**

2025-07-07 - 2025-07-13

* Command Line C++ Development - Mathew Benson - [https://youtu.be/a9C0KgQcLYU](https://youtu.be/a9C0KgQcLYU)
* A constexpr Virtual CRTP Comparison - Amir Kirsh - [https://youtu.be/QywrIVM1bos](https://youtu.be/QywrIVM1bos)
* C++ Type Traits Without Compiler Intrinsics - The Promise of Static Reflection in C++ - [https://youtu.be/EK74rV1M7uc](https://youtu.be/EK74rV1M7uc)

2025-06-30 - 2025-07-06

* Essential C++ Tips and Tricks for the Ultimate Cpp Performance - Andreas Fertig - [https://youtu.be/\_lwuqH72ycM](https://youtu.be/_lwuqH72ycM)
* Keynote: How To Improve Software Innovation Through Diversity - Sejal Gupta - [https://youtu.be/ym8mt\_LGWew](https://youtu.be/ym8mt_LGWew)
* How to Write a Base Level Cpp Library for Safety Critical Software in C++ - Anthony Williams - [https://youtu.be/NWTowFQ1c0I](https://youtu.be/NWTowFQ1c0I)

**ACCU Conference**

2025-07-07 - 2025-07-13

* The CUDA C++ Developer Toolbox - Bryce Adelstein Lelbach - [https://youtu.be/tDegOeivJs4](https://youtu.be/tDegOeivJs4)
* Mental Health in Software Development - Tanzt kaputt, was euch kaputt macht! - Dom Davis - [https://youtu.be/gbs-qMIlYUg](https://youtu.be/gbs-qMIlYUg)
* Heaps Don’t Lie - Guidelines for Memory Allocation in C++ - Mathieu Ropert - [https://youtu.be/74WOvgGsyxs](https://youtu.be/74WOvgGsyxs)

2025-06-30 - 2025-07-06

* The Next Coding Horizon - Proactive LLMs for Enhanced Productivity - Anastasia Kazakova - [https://youtu.be/ak7Q6TEOJnQ](https://youtu.be/ak7Q6TEOJnQ)
* The C++ Execution Model - Bryce Adelstein Lelbach - [https://youtu.be/6zq5ZmCvldU](https://youtu.be/6zq5ZmCvldU)

**ADC**

2025-07-07 - 2025-07-13

* A Spatial Audio Primer - Emma Fitzmaurice - [https://youtu.be/FOBPHBdi2gE](https://youtu.be/FOBPHBdi2gE)
* Auralization and Active Sound Design with Spatial Audio on a Vehicle Simulator - Joshua Chaiphas - [https://youtu.be/ZjAyrx6JVbc](https://youtu.be/ZjAyrx6JVbc)
* Guide to C++ ValueTrees - The Secret Weapon of JUCE - Brett g Porter - [https://youtu.be/usUz6CHl-Es](https://youtu.be/usUz6CHl-Es)

2025-06-30 - 2025-07-06

* Branch-Free Oscillators for Virtual Analog Software Synthesizer Applications in C++ - Angus Hewlett - [https://youtu.be/5Les61Hh46w](https://youtu.be/5Les61Hh46w)
* Spatial Localization and Techniques for Synthesizing Real-Time Binaural Audio for Headphones - Harsha Vardhan Rapeti - [https://youtu.be/A1XHIy1GgNQ](https://youtu.be/A1XHIy1GgNQ)
* Debugging Audio Content With Visuals - A Debugger Extension and Some Other Helpful Tools - Maxime Coutant - [https://youtu.be/tZMA49ZnMbQ](https://youtu.be/tZMA49ZnMbQ)

https://redd.it/1lzqie7
@r_cpp

Читать полностью…

C++ - Reddit

Suggest some code editors for C++ in android



https://redd.it/1lzjkeg
@r_cpp

Читать полностью…

C++ - Reddit

This-pointing Classes
https://biowpn.github.io/bioweapon/2025/07/13/this-pointing-classes.html

https://redd.it/1lzdfu8
@r_cpp

Читать полностью…

C++ - Reddit

Hungarian Notation, for us who use it

**Note:** *Most developers aren't fans of Hungarian Notation, and that's totally fine. This thread is for those of us who do use it, and how to make it effective. Let's discuss this niche area; we know we're a small minority*

# Hungarian Notation

**How do you use this style to maximize your effectiveness? Do you have any tips?**

To start I can inform the most important areas for me using Hungarian.

For me, Hungarian Notation is a technique to maximize the speed of visually processing and understanding code. Three main areas for speed

### Filtering out unimportant code

I rarely "read" code, I **scan** it. My eyes typically focus on columns 5-40 in the editor. I also always have a thin line above each method in `*.c, *.cpp` files. This line marks where a method begins. This pattern speeds up scrolling through code. My scroll step is set to 10 lines, so the slightest tick on scroll wheel moves me 10 lines up or down. I also use a Logitech mouse with a free-spinning scroll wheel, allowing me to scroll about 500 lines with a single finger movement. The line above each method helps my eye catch the method name when scrolling fast through the code.

example:

```c
/** ---------------------------------------------------------------------------
* @brief describe method
* ...
*/
void names::reserve(size_t uSize)
{
}
```

When scanning code, my eye only sees the prefixes, and that's where Hungarian Notation helps me filter out less important elements. Prefixes for primitive types show me what I can skip over.

### Minimizing abbreviations and ensuring code consistency

The only abbreviations allowed are those in a predefined list for the project. All these abbreviations must be self-explanatory to the team. They should essentially understand what the abbreviation means without any explanation. Example: an integer variable might be `iSomeName`. All programmers on the team can understand each other's code, and it's easy to read the code even outside of editors.

Hungarian Notation helps prevent cryptic names (often abbreviations) and ensures variables have better names. Awkward code often looks "ugly" when Hungarian Notation is practiced, making bad code more apparent. Hungarian Notation itself isn't particularly "pretty." Thats makes bad code even more uggly.

For me, the most important task isn't to show the type (though that helps), but rather to quickly find **important code**. Often, important code is only a fraction of other code (under 10%).

### Using suffixes to indicate reach

I end global methods or variables with `_g`, instead of starting with `gSomeName` as many do. This is a less critical marker, more about understanding the consequences of changing a value and comprehending the code as a whole, which is why this type of marking is at the end (its not something that improves speed). Debug and static variables have their own markers, becoming `*_d` for debug and `*_s` for static. I always add an underscore "\_".

### AI and Hungarian Notation

When I look at unfamiliar code, perhaps something interesting on GitHub or elsewhere online, I usually ask an AI to rewrite the code and I pre train AI with the style. I have a template with Hungarian Notation as the coding style, and once the AI rewrites it, I can read the code without much trouble. This makes even large amounts of code quickly "readable."

I also find that AI works much better with Hungarian Notation. The AI manages to name things more effectively, and I don't have to rewrite too much.

### Mental Stress

This is not for speed but more to make programming fun.
For me, this might be the most significant effect. Hungarian Notation means I can almost always understand code, regardless of who wrote it. It remains readable without needing to try to remember thing and I can focus on what the code actually does and how it works. The need to figure out what variables are almost completely disappears, which is perhaps the worst part of other coding styles. This means I don't have to waste energy memorizing the code, making

Читать полностью…

C++ - Reddit

Using &vector::at(0) instead of vector.data()

I have vector access like this:

memcpy(payload.data() + resolved, buf.data(), len);

I'd like bounds checks in release mode and thought about rewriting it into:

memcpy(&payload.at(resolved), &buf.at(0), len); // len > 0 is assumed

But I don't think it's idiomatic and defeats the purpose of the .data() function. Any thoughts?

https://redd.it/1lymbig
@r_cpp

Читать полностью…

C++ - Reddit

Generate trello/kanban boards from source code for project management

Currently working on a [Trello/Kanban-like](https://en.wikipedia.org/wiki/Comparison_of_scrum_software) tool to manage planning and remember programming tasks.

What differentiates it from conventional systems is that task information is stored directly within the code itself, rather than in a separate database.

Personally, I've always felt it was suboptimal to store information and other code-related details outside of the codebase. And very anoying that you cant link into the code.

Why put this in "cpp", I am C++ developer and this is the focus for this tool,

---

*The Tool: An Advanced Search application*

To get to the core of my **question**: the tool is essentially an **advanced search engine** that can find and collect information from source code. I've progressed to the point where it can search for multiple values, not just a single string.

For example, it can search for `#task #database`, and if both of these values are present on a single line, it registers as a hit. Combining words in this way allows for quite sophisticated code discovery.

However, **extracting** information from the code without cluttering it too much isn't as straightforward.

My idea is to implement a **flexible key-value logic** that's easy to adapt.

Here are some examples of how it could look:

* `// [type: task] [user:per] [tag: database, sqlserver] [description: information about the task] [status=todo]`
* `// type=task tag=database tag=user description="information about the task"`
* `// {type:task,priority:high,tag:database,tag:user,description:"information about the task", status=done}`

The above formats is not that difficult to create queries for to scan code after and match and extract information from to create an overview board. Same query will match all formats.

- Does this clutter code to much or cause to much unrelated code modifications in repository? If the task is close to whats going to be worked on in the code my guess is that its not that problematic
- What type of information do developers need for these task? Normally these descriptions in kanban tools are short, sometimes you want a history but that is solvable within the code
- Are there better formats to describe and is the key-value bad, is there maybre a better format. Key-value is something most developers are used to so thats the reason now

Link to the tool on github: https://github.com/perghosh/Data-oriented-design/releases/tag/cleaner.1.0.0

https://redd.it/1ly3oz3
@r_cpp

Читать полностью…

C++ - Reddit

C++, Autonomous Driving and future work opportunities

Hello guys.

I start by saying I'm new to this forum, I'm young and I will ask dumb questions in this post.
Would you say that learning C++ to work in robots/autonomous driving project, will help me, in the future, to land jobs at even big tech companies?
All I hear talk about is JS and Python.

Although I think it'll be much easier to learn those languages after having worked on the previously stated project, I'm still scared that I'll waste my time running after non-profitable projects (yes I care about money a lot unfortunately and I connect a good 30% of my worth with how much money I make)

Thank you guys.

https://redd.it/1ly1kel
@r_cpp

Читать полностью…

C++ - Reddit

[https://homeofficemedia.blog.gov.uk/electronic-travel-authorisation-eta-factsheet-january-2025/](https://homeofficemedia.blog.gov.uk/electronic-travel-authorisation-eta-factsheet-january-2025/)

https://redd.it/1m0msvl
@r_cpp

Читать полностью…

C++ - Reddit

Just graduated & CPP Jobs

Hey everyone!

I’ve recently graduated in CS.

I absolutely love cpp, making high performant / detail oriented applications, concurrency, OSes, networks, and all that stuff, but not really into eletronics/embedded nor I find the QoL / pay interesting in comparison to those as, say, web dev jobs.

I’m writing to ask if are there SWE jobs that look for people who are are able to write good cpp, high performant code, this kind of all-rounded engineer that understands the lower-level stuff? Where do you find these jobs? Or may you share the areas you’re working in?

Apologies if this is not the most suitable sub for these questions.

Thanks in advance!

https://redd.it/1m0lj6q
@r_cpp

Читать полностью…

C++ - Reddit

C++: how to implement lazy evaluation + SIMD for vector operations: V = v1 + v2 - k*v3;

I have developed a fully functional expression template `Vector<T>` class that supports delayed (lazy) evaluation, enabling expressions such as `V = v1 + v2 - 3.14 * v3`. The underlying data of `Vector` is stored contiguously and aligned to 32 or 64 bytes for efficient SIMD access.

For large vectors—typically with over one million elements—we aim to enable SIMD acceleration for arithmetic operations. In simple cases like `V = v1 + v2`, SIMD can be directly implemented within the `VectorAdd` expression (e.g., via an `evaluate()` function). However, when either `lhs` or `rhs` in `VectorAdd(lhs, rhs)` is itself an expression rather than a concrete `Vector<T>`, the `evaluate()` function fails, since intermediate expressions do not own data.

I wonder if there are any good C++ examples on GitHub or elsewhere for the solution of fully SIMD-enabled lazy evaluation.

https://redd.it/1m0deq3
@r_cpp

Читать полностью…

C++ - Reddit

I scraped 100k C++ jobs directly from corporate websites










I realized many roles are only posted on internal career pages and never appear on classic job boards.
So I built an AI script that scrapes listings from 70k+ corporate websites.

Then I wrote an ML matching script that filters only the jobs most aligned with your CV, and yes, it actually works.

You can try it here (for free).

(If you’re still skeptical but curious to test it, you can just upload a CV with fake personal information, those fields aren’t used in the matching anyway.)

https://redd.it/1m0d43z
@r_cpp

Читать полностью…

C++ - Reddit

asio-awaitable-future: Convert std::future to asio::awaitable seamlessly

# 🚀 asio-awaitable-future: Bridge std::future and asio coroutines

Hey r/cpp! I've been working on a header-only C++20 library that solves a common problem when working with asio coroutines.

# The Problem

When using asio coroutines, you often need to integrate with existing async code that returns `std::future<T>`. Direct usage blocks the IO thread, which defeats the purpose of async programming.

# The Solution

My library provides a simple `make_awaitable()` function that converts any `std::future<T>` to `asio::awaitable<T>` without blocking:

// Before: This blocks the IO thread
auto result = future.get();

// After: This doesn't block
auto result = co_await asio_future::make_awaitable(std::move(future));

# Key Features

✅ Header-only (easy integration)
✅ Non-blocking (uses thread pool)
✅ Exception-safe
✅ C++20 coroutines + asio
✅ MIT licensed

# Example Use Cases

* Blocking tasks
* Error handling in future
* CPU-intensive tasks

**GitHub:** [https://github.com/xialeistudio/asio-awaitable-future](https://github.com/xialeistudio/asio-awaitable-future)

Would love to hear your thoughts and feedback! 🙏

# Questions for the community:

1. Have you encountered similar challenges with asio integration?
2. Any suggestions for additional features?
3. Performance optimization ideas?

https://redd.it/1m064y1
@r_cpp

Читать полностью…

C++ - Reddit

`generator`'s `Allocator` template parameter is redundant

While implementing a generator type with a slightly different interface (https://github.com/jhcarl0814/ext\_generator ), I found that the `Allocator` template parameter is only used during construction and not used when the generator is traversed, dereferenced or destroyed. (So maybe it's OK to have `Allocator` present only during construction (e.g. in parameter list) but absent after that?) Then I tried to remove the `Allocator` template parameter from the type and the generator still supports custom allocators. (Callers can still "provide no arguments" when callees want to use custom **default-constructible** allocators.)

Examples without custom allocator:

ext::generator_t<std::string> f() { co_yield std::string(); }
auto c = f();

ext::generator_t<std::string> l = []() -> ext::generator_t<std::string> { co_yield std::string(); }();

Examples with custom allocator:

ext::generator_t<std::string> f(std::allocator_arg_t, auto &&) { co_yield std::string(); }
auto c = f(std::allocator_arg, allocator);

ext::generator_t<std::string> l = [](std::allocator_arg_t, auto &&) -> ext::generator_t<std::string> { co_yield std::string(); }(std::allocator_arg, allocator);

Examples with custom default-constructible allocator:

ext::generator_t<std::string> f(std::allocator_arg_t = std::allocator_arg_t{}, std::allocator<void> = {}) { co_yield std::string(); }
auto c = f();

ext::generator_t<std::string> l = [](std::allocator_arg_t = std::allocator_arg_t{}, std::allocator<void> = {}) -> ext::generator_t<std::string> { co_yield std::string(); }();

Does anyone here know the rationale behind that template parameter, like what can not be achieved if without it?

I also noticed that "std::generator: Synchronous Coroutine Generator for Ranges" (https://wg21.link/p2502 ) talks about type erasing the allocator and some `std::generator` implementations store function pointers invoking allocator's member functions saying they're doing type erasing. But my implementation does not use any function pointers taking `void*` and still can call the right allocator, because coroutines are already manipulated by type erased handles??? Is there something wrong with my implementation?

https://redd.it/1m02j38
@r_cpp

Читать полностью…

C++ - Reddit

-Wexperimental-lifetime-safety: Experimental C++ Lifetime Safety Analysis
https://github.com/llvm/llvm-project/commit/3076794e924f

https://redd.it/1lzz8d0
@r_cpp

Читать полностью…

C++ - Reddit

AI will replace programmers—just not yet, because it still generates very extremely inefficient code.
https://nullonerror.org/2025/07/12/ai-will-replace-programmers-just-not-yet-because-it-currently-generates-extremely-inefficient-code/

https://redd.it/1lzr1zz
@r_cpp

Читать полностью…

C++ - Reddit

Sourcetrail (Fork) 2025.7.11 released

Hi everybody,

Sourcetrail 2025.7.11, a fork of the C++/Java source explorer, has been released with these changes:

C/C++: Add indexing of `constexpr`
C/C++: Replace most msvc compiler switches with the correct clang switches (Fixes a long standing issue "no such file or directory (sourcetrail is treating MSVC options as file/dir)"
Java: Add support for Java 24
C/C++/Java: Revised the list of keywords for syntax highlighting

https://redd.it/1lzoc6n
@r_cpp

Читать полностью…

C++ - Reddit

Little adventure in pursuit of errors. The Battle for Wesnoth!
https://pvs-studio.com/en/blog/posts/cpp/1261/

https://redd.it/1lzjoqg
@r_cpp

Читать полностью…

C++ - Reddit

programming much more enjoyable.

These are the most important advantages for me; there are others, but they're not as important.

The favorite style I us is the following

**Types**

| Postfix | Description | Sample |
| ------------ | ----------- | ------ |
| `b`* | **boolean** | `bool bOk, bIsOk, bIsEof, bResult;` |
| `i`* | **signed integer** (all sizes) | `int iCount;` `int64_t iBigValue;` `int16_t iPosition; char iCharacter;` |
| `u`* | **unsigned integer** (all sizes) | `unsigned uCount;` `uint64_t uBigValue;` `uint8_t uCharacter;` `size_t uLength;` |
| `d`* | **decimal values** (double, float) | `double dSalary;` `float dXAxis;` `double dMaxValue;` |
| `p`* | **pointer** (all, including smart pointers) | `int* piNumber;` `int piNumber[20];` `void* pUnknown;` `std::unique_ptr<std::atomic<uint64_t>[]> pThreadResult;` |
| `e`* | **enum values** | `enum enumBodyType { eUnknown, eXml, eJson };` `enumBodyType eType = eJson;` |
| `it`* | **iterator** | `for( auto it : vectorValue ) {...}` `for( auto it = std::begin( m_vectorOption ), itEnd = std::end( m_vectorOption ); it != itEnd; it++ ) {...}` |
| `m_`* | **member variables** | `uint64_t m_uRowCount;` `std::vector<column> m_vectorColumn;` `uint8_t* m_puTableData = nullptr;` |
| `string`* | **all string objects** | `std::string_view stringName;` `std::string stringName;` `std::wstring stringName;` |
| *`_` | **view declaration** | `boost::beast::http::file_body::value_type body_;` |


**Scope**

| Prefix | Description | Sample |
| ------------ | ----------- | ------ |
| *`_g` | **global reach**, global methods and variables | `CApplication* papplication_g;` |
| *`_s` | **static**, like free functions and static variables within objects and methods with file scope | `static std::string m_stringCity_s;` |
| *`_d` | **debug names**, names that are used for debugging | `std::string stringCommand_d;` |


https://redd.it/1lys9y0
@r_cpp

Читать полностью…

C++ - Reddit

Hungarian Notation, for us who use it

Note: Most developers aren't fans of Hungarian Notation, and that's totally fine. This thread is for those of us who do use it, and how to make it effective. Let's discuss this niche area; we know we're a small minority

# Hungarian Notation

How do you use this style to maximize your effectiveness? Do you have any tips?

To start I can inform the most important areas for me using Hungarian.

For me, Hungarian Notation is a technique to maximize the speed of visually processing and understanding code. Three main areas for speed

### Filtering out unimportant code

I rarely "read" code, I scan it. My eyes typically focus on columns 5-40 in the editor. I also always have a thin line above each method in *.c, *.cpp files. This line marks where a method begins. This pattern speeds up scrolling through code. My scroll step is set to 10 lines, so the slightest tick on scroll wheel moves me 10 lines up or down. I also use a Logitech mouse with a free-spinning scroll wheel, allowing me to scroll about 500 lines with a single finger movement. The line above each method helps my eye catch the method name when scrolling fast through the code.

example:

/** ---------------------------------------------------------------------------
* @brief describe method
* ...
*/
void names::reserve(size_t uSize)
{
}


When scanning code, my eye only sees the prefixes, and that's where Hungarian Notation helps me filter out less important elements. Prefixes for primitive types show me what I can skip over.

### Minimizing abbreviations and ensuring code consistency

The only abbreviations allowed are those in a predefined list for the project. All these abbreviations must be self-explanatory to the team. They should essentially understand what the abbreviation means without any explanation. Example: an integer variable might be iSomeName. All programmers on the team can understand each other's code, and it's easy to read the code even outside of editors.

Hungarian Notation helps prevent cryptic names (often abbreviations) and ensures variables have better names. Awkward code often looks "ugly" when Hungarian Notation is practiced, making bad code more apparent. Hungarian Notation itself isn't particularly "pretty." Thats makes bad code even more uggly.

For me, the most important task isn't to show the type (though that helps), but rather to quickly find important code. Often, important code is only a fraction of other code (under 10%).

### Using suffixes to indicate reach

I end global methods or variables with _g, instead of starting with gSomeName as many do. This is a less critical marker, more about understanding the consequences of changing a value and comprehending the code as a whole, which is why this type of marking is at the end (its not something that improves speed). Debug and static variables have their own markers, becoming *_d for debug and *_s for static. I always add an underscore "_".

### AI and Hungarian Notation

When I look at unfamiliar code, perhaps something interesting on GitHub or elsewhere online, I usually ask an AI to rewrite the code and I pre train AI with the style. I have a template with Hungarian Notation as the coding style, and once the AI rewrites it, I can read the code without much trouble. This makes even large amounts of code quickly "readable."

I also find that AI works much better with Hungarian Notation. The AI manages to name things more effectively, and I don't have to rewrite too much.

### Mental Stress

This is not for speed but more to make programming fun.
For me, this might be the most significant effect. Hungarian Notation means I can almost always understand code, regardless of who wrote it. It remains readable without needing to try to remember thing and I can focus on what the code actually does and how it works. The need to figure out what variables are almost completely disappears, which is perhaps the worst part of other coding styles. This means I don't have to waste energy memorizing the code, making

Читать полностью…

C++ - Reddit

GUESSE WHO LEARNED TO DO A CALCULATOR

>

https://redd.it/1lydyia
@r_cpp

Читать полностью…

C++ - Reddit

What are good learning examples of lockfree queues written using std::atomic

I know I can find many performant queues but they are full implementations that are not great example for learning.

So what would be a good example of SPSC, MPSC queues written in a way that is fully correct, but code is relatively simple?

It can be a talk, blogpost, github link, as long as full code is available, and not just clipped code in slides.

For example When Nanoseconds Matter: Ultrafast Trading Systems in C++ - David Gross - CppCon 2024

queue looks quite interesting, but not entire code is available(or i could not find it).

https://redd.it/1lxyko5
@r_cpp

Читать полностью…

C++ - Reddit

How to flatten the variant?

I have `std::variant<std::variant<int, char>, char>` I need to first flatten it and then take the unique types from it. The result should be std::variant<int,char>. How to do that? I have implemented unique\_variant using templates. Also done flattening. But couldn't able to compose them together.

But when I do

using ResultType = unique_variant<flat_variant<std::variant<InnerType<A>, InnerType<B>>>>;

It is giving me type as

std::variant<std::variant<int, char, char>> but I want std::variant<int, char>

template <typename T, typename... List>
constexpr bool is_in_list = (std::is_same_v<T, List> || ...);

template <typename... Types> struct flat_type_container {
using type = flat_type_container<Types...>;
using variant = std::variant<Types...>;
};

template <typename First, typename... Types>
struct flat_type_container<First, flat_type_container<Types...>> {
using type = flat_type_container<First, Types...>;
};

template <typename First, typename... Rest> struct unique_types {
using type =
typename std::conditional_t<!is_in_list<First, Rest...>,
typename flat_type_container<First,
typename unique_types<Rest...>::type>::type,
typename unique_types<Rest...>::type>;
};

template <typename First> struct unique_types<First> {
using type = flat_type_container<First>;
};

template <typename... Types> struct get_unique_variant {
using container = typename unique_types<Types...>::type;
using variant = typename container::variant;
};

template <typename... List>
using unique_variant = typename get_unique_variant<List...>::variant;



template <class T> struct is_variant : std::false_type { };
template <class... Ts>
struct is_variant<std::variant<Ts...>> : std::true_type { };
template <class T> constexpr bool is_variant_v = is_variant<T>::value;

template <class V1, class V2> struct concat_variants;
template <class... Ts, class... Us>
struct concat_variants<std::variant<Ts...>, std::variant<Us...>> {
using type = std::variant<Ts..., Us...>;
};

template <class T> struct flat_variant {
using type = std::variant<T>;
};

template <class T>
struct flat_variant<std::variant<T>> : flat_variant<T> { };

template <class First, class... Rest>
struct flat_variant<std::variant<First, Rest...>> {
private:
using flat_first = typename flat_variant<First>::type;
using flat_rest =
typename flat_variant<std::variant<Rest...>>::type;

public:
using type =
typename concat_variants<flat_first, flat_rest>::type;
};



https://redd.it/1lxyfpa
@r_cpp

Читать полностью…
Subscribe to a channel