C++ - Reddit
223 subscribers
48 photos
8 videos
24.7K links
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
Download Telegram
Binary debug for nested big ass structures.

Heyaa,

So recently I had to compare binaries in the layout of multi level nested big fat structures. I surprised to find that there are no good tools to do that. The best i could find was watch section in visual studio. I have tried another tool, WinDbg this doesn’t work well with macros and arrays. To make matters worse, this big ass structure has offsets that point beyond of the structure. There is no good tools which automatically tells values for each field

Tldr: i have custom buffer layout with multiple nested level structures.

https://redd.it/1sssd6w
@r_cpp
Libraries for general purpose 2D/3D geometry vocabulary types?

I work in the geospatial industry and have worked on plenty of large projects that have their own internal geometry libraries. Some good, some bad, most with interesting historical choices. I recently joined a new project that hasn't yet really defined its vocabulary types yet, and I'm finding that extremely inconvenient, so I'm looking around at what is common

The kinds of things I'm looking for are:

`Vector<typename T, size_t Dimension>`: Basically a `std::array<T,Dimension>` with a vector-like API
Point: A wrapper around a Vector with point semantics
`Size`: A wrapper around a `Vector` with size semantics
Range: A basic min/max interval
`AxisAlignedBox`: A set of `Range`s in N dimensions
RotatedBox: A AxisAlignedBox with a basis Vector
`Polyline`: A `std::vector<Point>` assumed to be open
Polygon: A std::vector<Point> assumed to be closed
`Matrix`: An NxM matrix
...

I know there are plenty of vector/matrix/linear algebra libraries out there, often focused on flexibilty and raw computational performance. I'm more interested in nice vocabulary types that implement proper semantics via convenient methods and operators.

It seems these things are often provided by game engines, but pulling in an entire game engine for a non-gaming project feels silly.

So if you were starting a new, greenfield C++ application dealing with 3D geometric data, which existing library, if any, would you reach for?



https://redd.it/1stif6d
@r_cpp
Good Resource for Topics

Hi,

Please suggest good resource for Multithreading, Smart Pointers and Copy Constructor.

Thanks

https://redd.it/1stj0ka
@r_cpp
Maintaining libraries in multiple formats are a bad idea

Library authors shouldn't maintain header only/ header source/ module libraries in one repo. It is a bad idea.

First of all library authors assume if tests succeed on header only format it also works on modules, which is not correct.

Second, the compilation and packaging becomes very ugly, it looks similar to c++ standard versioning macros. Like a project should only compile on one standard, and the other users should either stick to a version/branch or kick rocks.

It is very pleasant to just use modules for libraries, everything is clean. By adopting a support everything approach, library authors harm themselves first and then everyone else because everything lags down.

https://redd.it/1sufvwe
@r_cpp
CppCast Looking for Guests

As you may be aware - I've restarted [CppCast](https://cppcast.com/) (every 4th week in a rhythm with [C++Weekly](https://www.youtube.com/@cppweekly)) with u/mropert as my cohost.

We are trying to focus on new people and projects who have never before been on CppCast. I have been trolling the show and tell posts here for potential guests and projects.

But I want to ask directly - if you are interested in coming on the podcast to talk about your project / presentation / things you are passionate about and have never before been on CppCast, please comment!

A couple of notes:

* please don't be offended if I don't respond to your post, I have a very busy travel and conference schedule coming up (I'll see you at an upcoming conference!)
* if you're interested please pay attention for a DM so we can get the conversation started.
* being only 1 podcast per month, we don't need a ton of guests, and it might be a few months before your specific interview gets aired

Thank you everyone!




https://redd.it/1suls4e
@r_cpp
Using Reflection For Parsing Command Line Arguments

I've been very excited about reflection so I built a small library to pass command line arguments

Basic example:

struct Args
{
std::string firstname;
int age;
bool active;
};

// ./program --first-name John --age 99 --active

const auto args = clap::parse<Args>(argc, argv);

assert(args.first
name == "John");
assert(args.age == 99);
assert(args.active);

More interesting example:

struct Args
{
[= clap::Description<"host to connecto to">{}]
std::string host = "localhost";

[=clap::ShortName<'p'>{}]
std::uint16t port;

[[=clap::Env<"RETRY
COUNT">{}]]
std::uint32t retrycount;

std::optional<std::string> logfile;

[[=clap::ShortName<'e'>{}]]
bool encrypted;

[[=clap::ShortName<'c'>{}]]
bool compressed;

[[=clap::ShortName<'h'>{}]]
bool hashed;
};

// ./program -p 8080 -ec

const auto args = clap::parse<Args>(argc, argv);

assert(
args.host == "localhost");
assert(args.port == 8080);
assert(args.retry
count == std::stoul(std::getenv("RETRYCOUNT")));
assert(!args.log
file);
assert(args.encrypted);
assert(args.compressed);
assert(!args.hashed);

The amount of code to handle this is actually quite minimal < 500 lines.

There's a few modern goodies that make this code work:

Reflection \[[P2996](https://isocpp.org/files/papers/P2996R13.html)\]
Annotations for Reflection [P3394\]
Contracts \[[P2900](https://isocpp.org/files/papers/P2900R14.pdf)\]
constexpr exceptions [P3068\]

I guess we don't know what "idiomatic" reflection usage is like yet, I'm interested to come back to this code in a years time and see what mistakes I made!

Link to the code: https://github.com/nathan-baggs/clap

Any feedback, queries, questions are welcome!

https://redd.it/1sv4w78
@r_cpp
C++ Modules: clangd, go or no go debating on pulling the modules plug on a project

Every now and then, someone asks how C++ modules are going. I am a lead dev (mentioned not for bragging but to emphasize the crushing weight of responsibility) for a robotics project, as we are making a CV codebase from scratch, I have the opportunity to choose the architecture and conventions of the code (even more crushing responsibility).

I have gotten some C++23 codebases with modules set up; however, whenever adding a new module, I have to recompile to get clangd to not spam extra errors. I have been starting to get second thoughts with pushing modules all the way. To avoid the gcc-clangd stuff, I ended up specifying the compiler as clang (although I could use clangd compiler flag remove/add).

The codebase is at a point where I can relatively, easily pull the plug on modules.

Requirements:

1. No vscode or intellisense - I'm tired of vendor lock
2. Clangd, so we have neovim-coc-clangd + vscodium support
3. Sits well with cmake
4. Not really has to sit too well with clangd, as long as it sits well with compile_commands.json since that is a bit more of a decentralized standard for code completion etc.
5. As much as I would be willing to learn to code without code completion, I would prefer to have enough leeway to radicalize newbies to a nvim plugin with vscodium or neovim-coc-clangd + telescope itself \^_\^

Ideals:

1. Codebase can work with as many compilers as possible (as long as they support #pragma once because the time spent on botched header guards + incoming newbies concerns me enough to diverge a lil' bit from standard C++. Also, our CV codebase is one of those projects that isn't meant to be portable. All of our portable code does use header guards to please the great bjorne stroustroup
2. Ease with other code completion tools

Why (for the curious):

1. Vendor lock sucks
2. Proprietary vendor lock sucks even more
3. I have a bone to pick with microslop
4. Because as an embedded project, vscode's oddities disrupts portions of our toolchain from time to time
5. Even though the CV codebase is not embedded, the fact that vscode support for modules was much harder to get than neovim/clangd just left a bad taste in my mouth. Call me unskilled, but it convinced the newer devs to learn modern C++ on pure command line rather than a shiny GUI-based IDE setup :P

For the curiouser: no, we don't use github anymore :P

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