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
Considering an IDE switch from VS Code
Hello I work mainly with c++17-20 for embedded on STM32. Using custom drivers and build scripts with Meson.
I'm considering switching to an IDE such as CLion, because I feel VS Code is lacking a bit in the C++ department, but everything else is excellent.
Can anyone tell me their experience with switching from VS Code to Clion or similar C++ IDE.
(I run Mac/Linux, so Visual Studio is unfortunately out of the question)
https://redd.it/1aredn6
@r_cpp
Registration for C++Now 2024 is now open!
https://cppnow.org/announcements/2024/02/2024-registration-is-open/
https://redd.it/1ar5u3o
@r_cpp
Man in court case is asked about a line of in C++ to prove he wrote it
https://x.com/arthur_van_pelt/status/1757781329427493319?s=46&t=RTDvKPRiB0sw5_0xcFETPg
https://redd.it/1aqqxm4
@r_cpp
namespace in header, but using declaration in cpp file
Hey, in my company they tend to do this:
// xyz.h
namespace blah {
struct Xyz {
void foo ();
};
} // namespace blah
// xyz.cpp
using blah::Xyz;
void Xyz::foo () {}
namespace blah {
void Xyz::foo () {}
}
using
, so please stick to it, and don't do namespace blah {
in a cpp". Mutex with conditional variable
Hi everyone
I am new to multithreading Please forgive for any mistake.
So recently i was solving a problem on leetcode dining philospher with 5 philosphers. I used the strategy that the odd numbered philosher will pick left fork first and the even numbered philospher will pick right fork first.
Code is written without conditional variable. Each thread corresponds to philospher.
My question is lets say thread t1 gets lock on m1 and m2
and then t2 comes tries lock on m3 and gets it and then tries to lock on m2 and don't get.
Doubts
1) As you saw in below code there is no conditional variable and it passes also when i submit. So my doubt is why we didn't get time limit exceeded when t2 tries to lock on m2 and it didn't get, so it went to sleep again and there is notifying mechanism here, so how operating systems handled it. Was t2 continuulsy polling in for the lock on m2 when it didn't get for the first time ? Or OS have same waiting queue associated to each mutex variable in which all threads are placed who didn't get the access in first time and then it will automatically give the lock when lock is available by popping one thread.
Please correct if my understand is false. Thanks.
question link: https://leetcode.com/problems/the-dining-philosophers/description/
class DiningPhilosophers {
int n;
vector<mutex>lcks;
public:
DiningPhilosophers() {
n = 5;
lcks = vector<mutex>(n);
}
void wantsToEat(int p,
function<void()> pickLeftFork,
function<void()> pickRightFork,
function<void()> eat,
function<void()> putLeftFork,
function<void()> putRightFork) {
int left = p % 5;
int right = (p + 1) % 5;
if(p % 2){
lcksleft.lock();
//cout<<"pick left " + (tostring(p))<<endl;
lcks[right].lock();
//cout<<"pick right " + (tostring(p))<<endl;
pickLeftFork();
pickRightFork();
eat();
putLeftFork();
putRightFork();
lcksright.unlock(); // order here caused tle
lcksleft.unlock();
} else {
lcksright.lock();
lcksleft.lock();
pickLeftFork();
pickRightFork();
eat();
putLeftFork();
putRightFork();
lcksright.unlock(); // order here caused tle
lcksleft.unlock();
}
}
};
​
https://redd.it/1aqjsy9
@r_cpp
C++ Package Managers: The Ultimate Roundup | Modern C++ DevOps
https://moderncppdevops.com/pkg-mngr-roundup
https://redd.it/1apvh5b
@r_cpp
Fluent Design-based GUI Library for System Tray Applications
I have started a project to create a system tray application in Windows with a C++ single header.
There are similar projects, but this library is very simple and has no dependencies.
In the future, it will support cross-platform.
https://github.com/pit-ray/fluent-tray
https://redd.it/1aptafg
@r_cpp
Adding AddressSanitizer support to the Cheerp WebAssembly compiler
https://labs.leaningtech.com/blog/cheerp-asan
https://redd.it/1aps7q6
@r_cpp
Measuring Jitter
https://lucisqr.substack.com/p/measuring-jitter
https://redd.it/1apo34u
@r_cpp
clangd and clang conflict.
Hey so i need clangd for lsp and stuff. but need clang to compile as it produces more performant and optimized code than g++. i already have clangd installed but when i try to install clang it gives the following error:
​
​
error: failed to commit transaction (conflicting files)clang: /usr/bin/clangd exists in filesystem (owned by clangd)Errors occurred, no packages were upgraded.-> error installing repo packages
​
​
https://redd.it/1apj84j
@r_cpp
Proposal: introducing std::all<T>(T container) as an alias to std::make_pair(begin(container), end(container))
Unlocking some <algorithm> overloads like
> std::find( std::all(elements), val )
It’s about time the “begin(v), end(v)” repetition stops.
https://redd.it/1apaj38
@r_cpp
C++ Videos Released This Month - February 2024 (Updated to Include Videos Released 02/05/2024 - 02/11/2024)
This month the following C++ videos have been published to YouTube. A new post will be made each week as more videos are released
CppCon
01/29/2024 - 02/04/2024
Object Introspection: A C++ Memory Profiler - Jonathan Haslam & Aditya Sarwade - [https://youtu.be/6IlTs8YRne0](https://youtu.be/6IlTs8YRne0)
Plug-in Based Software Architecture for Robotics - Abishalini Sivaraman & Anthony Baker - https://youtu.be/Os6PoxvJfIQ
Is C++23 std::mdspan a Zero-overhead Abstraction? - Oleksandr Bacherikov - [https://youtu.be/9fRnSQkpNGg](https://youtu.be/9fRnSQkpNGg)
Embracing CTAD - Nina Ranns - https://youtu.be/pcroTezEbX8
How to Build Your First C++ Automated Refactoring Tool - Kristen Shaker - [https://youtu.be/torqlZnu9Ag](https://youtu.be/torqlZnu9Ag)
02/05/2024 - 02/11/2024
Robotics at Compile Time: Optimizing Robotics Algorithms With C++'s Compile-Time Features - https://youtu.be/Y6AUsB3RUhA
Symbolic Calculus for High-performance Computing From Scratch Using C++23 - Vincent Reverdy - [https://youtu.be/lPfA4SFojao](https://youtu.be/lPfA4SFojao)
C++ Object Lifetime: From Start to Finish - Thamara Andrade - https://youtu.be/XN\_\_qATWExc
Undefined Behavior in C++: What Every Programmer Should Know and Fear - Fedor Pikus - [https://youtu.be/k9N8OrhrSZw](https://youtu.be/k9N8OrhrSZw)
Robots Are After Your Job: Exploring Generative AI for C++ - Andrei Alexandrescu - https://youtu.be/J48YTbdJNNc
All of these talks can also be accessed at https://cppcon.programmingarchive.com where you can also find information on how to get early access to the rest of the CppCon 2023 videos and lightning talks.
Meeting C++
01/29/2024 - 02/04/2024
Advanced SIMD Algorithms in Pictures - Denis Yaroshevskiy - [https://www.youtube.com/watch?v=vGcH40rkLdA](https://www.youtube.com/watch?v=vGcH40rkLdA)
Tooling Intuition - Kevin Carpenter - https://www.youtube.com/watch?v=mmdoDfw9tIk
Design Patterns: The most common misconceptions - Klaus Iglberger - [https://www.youtube.com/watch?v=w-fkFyrbWbs](https://www.youtube.com/watch?v=w-fkFyrbWbs)
Memory Model: Get your shared data under control - Jana Machutová - https://www.youtube.com/watch?v=L5RCGDAan2Y
02/05/2024 - 02/11/2024
TDD for Microcontrollers - Daniel Penning - [https://www.youtube.com/watch?v=EvvJE0AYeZw](https://www.youtube.com/watch?v=EvvJE0AYeZw)
A Smooth Introduction to SYCL for C++20 afficionados - Joel Falcou - https://www.youtube.com/watch?v=-Lr0Xj\_lR4Y
Playing Video Games One Frame at a Time - Ólafur Waage - [https://www.youtube.com/watch?v=nYoIiUc3u3o](https://www.youtube.com/watch?v=nYoIiUc3u3o)
Using the filter view in practice - Nicolai Josuttis - https://www.youtube.com/watch?v=49ZYW4gHBIQ
​
https://redd.it/1ap4zvx
@r_cpp
Title: 🚀 Unveiling Electro Graphics API: Redefining the Future of Graphics in 2030! 🌌
Greetings, fellow Redditors!
I am thrilled to share a groundbreaking announcement with you today. After months of passion, dedication, and innovation, I am proud to introduce my latest project: Electro Graphics API! 🎮✨
What Sets Electro Apart?
Electro is not just another graphics API – it's a leap into the future of graphics technology. With capabilities surpassing industry standards like Vulkan and DirectX, Electro aims to redefine the landscape of graphics development. Expect unparalleled performance, advanced features, and a developer-friendly environment that empowers creativity.
Key Features:
✨ Cutting-edge rendering technology
✨ Unmatched performance and efficiency
✨ Enhanced graphical capabilities
✨ Intuitive developer tools
✨ Future-proof architecture for evolving needs
Why Electro?
In the ever-evolving world of graphics, Electro is designed to set new benchmarks. It goes beyond conventional expectations, providing developers with a powerful toolset to create immersive, stunning visuals that push the boundaries of what's possible.
Release Date: 2030
Mark your calendars! Electro is scheduled for an official release in 2030. This extended timeline allows for meticulous development and ensures that Electro arrives with the utmost quality and innovation.
Join the Revolution:
I invite developers, enthusiasts, and visionaries to join the Electro community. Share your thoughts, aspirations, and expectations for this groundbreaking project. Your input will shape the future of graphics technology.
Follow the Development:
Stay updated on Electro's journey by following me on Twitter and GitHub. Regular updates, sneak peeks, and community discussions await as we collectively shape the future of graphics.
This project is a labor of love, and I'm excited to embark on this journey with the incredible Reddit community. Let's push the boundaries of graphics together and make Electro a force to be reckoned with!
Eagerly anticipating the future,
[Your Reddit Username\]
https://redd.it/1ap0n04
@r_cpp
Writing and reading 0-255
Hi guys. What can I use to write and read, in order to deal with the full character set 0-255? I include the program that will prove that it doesn't work. This is the best write and read I could find. I'm using Visual C++ Thank you.
unsigned char Ch1;
int ix, iNumOut;
const string TEST_FILE = "T1.DAT";
// Write
ofstream testout(TEST_FILE, ios::binary);
for (ix = 0; ix <= 255; ix++)
testout << char(ix);
testout.close();
// Read
ifstream testin(TEST_FILE, ios::binary);
for (ix = 0; ix <= 255; ix++)
{
testin >> Ch1;
iNumOut = Ch1;
cout << iNumOut << ", ";
}
testin.close();
https://redd.it/1aowtcd
@r_cpp
Stuck at this curl linker error
So I am running below code -
varunshrivasta8/GA#main.cpp" rel="nofollow">https://replit.com/@varunshrivasta8/GA#main.cpp
I am getting following error
error LNK2019: unresolved external symbol __imp_curl_easy_strerror referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getAccessToken(void)" (?getAccessToken@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 1>curltest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getAccessToken(void)" (?getAccessToken@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 1>curltest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_setopt referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getAccessToken(void)" (?getAccessToken@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 1>curltest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_perform referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getAccessToken(void)" (?getAccessToken@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 1>curltest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_cleanup referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getAccessToken(void)" (?getAccessToken@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
I have already tried going to properties-> configuration -> linker-> input and providing library paths with additional dependency. Yet the problem is still there.
https://redd.it/1aoux5n
@r_cpp
Yet another functional library
Hey everyone, as a pet project (https://github.com/ninjanesto/yafl) I've been working on a functional concepts library. My idea is to study some concepts (mainly from haskell) and implement them in C++. I know monadic operations will arrive to c++ with the c++23 release but here I'm using c++17 for everything.
This library provides Monad classes for Maybe and Either types and also some functional concepts such as partial application, currying/uncurrying, lifting, etc. Most of the implementations try to reduce the need to explicitly provide the types, while trying to use for most cases auto deduction.
If you all could provide some feedback it would be awesome.
Thanks everyone
https://redd.it/1ard2pw
@r_cpp
mantis: blazing fast distance to surface computation
Hey everyone!
I've been working on a library that given some query point, can compute the distance to a surface (defined as a triangle mesh) called mantis: https://github.com/Janos95/mantis
It uses a very nice algorithm that was recently published. The authors of the paper actually published code as well. My implementation has three advantages, it has no dependency, is permissively licensed and is rewritten from scratch with a lot of low level optimizations (most importantly all the math is done using SIMD). That way it is 2-3x faster than the original implementation (for distance queries) and AFAIK it is the fastest code out there to compute the closest point.
I've also included two example uses cases of mantis in the repository. Let me know if this is useful for some folks. Also I'd be interested in any feedback you folks have!
https://redd.it/1aqsxm3
@r_cpp
Interoperability with Rust?
The Rust language is getting traction, and it covers the same use cases as C++ so I believe that in the future most of us in this forum will be using both of them. That led me to wonder if there are efforts to make it easy to integrate them, for example to maintain a project which uses both languages, or to make use of a library written in the other language.
https://redd.it/1aqmx9m
@r_cpp
Quant Finance, from the Programming side
For the Folks in Quantitative Finance developing mainly in C++:
So, I got interested in this fieldI think due to Maths😅, and... - my C++ and Python are good more C++ than Python, though; general Maths Calculus, Linear Algebra, Differential Equations, etc. as well.
Now, Probability and Statistics is something I'd need to work on. Never really needed to learn them, so I focused on other stuff.
Also, I'd need to learn Finance. That's not something I've done before either.
But the thing is: I don't intend to be on the more financial, analytical, decision making, etc. side of things true Finance people and/or Mathematicians would do better😂
So, my question is: Since I'd like to be more in the Programming side of things, I can't just set out to be an expert in all-things Probs, Stats, Stochastics, Finance, etc.
So, what are the key Maths topics that I should learn. I mean, the ones that you Devs had to learn, even though you mainly write Software. Some sort of common knowledge.
Or do you Quant Developers don't really go through the Maths and just program what comes from the folks on the top?
And yeah, in the meantime I'd be also doing some domain specific stuff in C++, since there's much difference between usual Application Development and Low-Latency Systems.
Thanks.
https://redd.it/1aqkqa2
@r_cpp
Prevent or warn on usage of std::map ?
The default insertion of a value when std::map [\] doesn't find a value for the key has to be one of the worst decisions in STL history (which is kind of impressive.) At work over the last year or so, we've had at least four, maybe five, bugs caused by this. It's so easy to do without thinking about it, and so easy to miss in a code review. And some of them had been there for many years and finally caused an issue, so no one was even looking for them.
Is there any way to prevent its use, or at least to warn on its use in MSVC? We use the built in static analyzer, and I don't see any warning related to that, though there are a lot of them and I may have missed something.
https://redd.it/1apuuv8
@r_cpp
Safety, Revisited
https://accu.org/journals/overload/32/179/teodorescu/
https://redd.it/1apwtl7
@r_cpp
New fully multithreaded version of C++ DataFrame was released
Version 3.0.0 release of C++ DataFrame is a very exciting one. Multithreading was completely redesigned in DataFrame with this release. DataFrame now uses a versatile thread-pool to implement parallel computing logic. Almost all DataFrame API’s/algorithms have a multithreaded version that kicks in for large datasets and when sufficient threads are available.
Consistent with before, DataFrame outperforms its competitors like Pandas and Polars (in some cases by many folds). But version 3.0.0 adds significant performance enhancement for large datasets.
Also, DataFrame documentation was enhanced recently. Code samples were added for every API. Explanations were added for concepts such as multithreading, SIMD, … and how to take advantage of them in DataFrame (and how not to fall into pitfalls).
C++ DataFrame was not meant to be a competitor to or being a better version of either Pandas or Polars. It was meant to enrich the C++ ecosystem and give C++ engineers a viable alternative so they can stay in C++ for both research and production. That’s why there is no Python port of DataFrame.
https://redd.it/1apsktp
@r_cpp
A Year of C++ Improvements in Visual Studio, VS Code, and vcpkg
https://devblogs.microsoft.com/cppblog/a-year-of-cpp-improvements-in-visual-studio-vs-code-and-vcpkg/
https://redd.it/1apqkri
@r_cpp
Learning C++ or Fullstack Development in Australia
Hi there. I checked out the roadmap.sh for fullstack development and it mentioned in the introductory phase that I should learn JavaScript, HTML, and CSS.
However, I was planning on doing a project in C++ because people say you should solve a problem, do something that your passionate about, or connect to a personal hobby to learn programming more efficiently (maybe a game or something).
Another thing was the topic of beginners thinking they need to learn many languages, people have advised against this as the underlying problem solving skills that you will develop learning a language will transfer to other languages, but also it's more fruitful to know one language well than it is to know the basics of a bunch of different languages.
I'm confused as to what I should do as the more common languages in Australian Internships, and grad roles seem to be HTML/CSS/JavaScript, Java, Python, should I just follow the C++ developer roadmap? I also need to do leetcode so i'd probably have to pick a language then as well.
My ultimate goal was to simply get a "Software Engineering" internship at any company in my penultimate year (2nd year, 2/3). I'm aware of frontend and backend, and I've chosen the goal of trying to be a fullstack developer as it seems most roles are fullstack.
Perhaps an example would be better to explain the situation. if I want to apply to a Java Internship at Canva, would they take me in as the "skills are trasnferrable" ?
What should I do, pursue a "passion project" in C++ connecting it to my gaming hobby, or fullstack development and make a website or something as an initial project. I think it'd be cool to recreate a movie reviewing website or something of the sort.
PROGRAMMING SKILL CONTEXT: Beginner about to start first year in CS, semester 1 having a intro to python class, and second semester having an intro to java class, currently doing CS50. I don't want to come off as cringe or anything, I just want to have a sort of roadmap/goal to follow.
https://redd.it/1apmmcw
@r_cpp
Is std::unordered_map still as bad as its reputation would indicate?
I have been benchmarking std vs abseil and ankerel, and all of them perform about the same for my use case (finding a known 12 byte key mapping to a pointer in a 1mm sized table). std has a reputation for being awful, but is that dated info? Or are its problems only evident in some use cases?
And yes, I've tried thrashing the cache in my benchmarks, even though that isn't really a concern for my program.
https://redd.it/1apd205
@r_cpp
What does exactly endl do that \n can't?
Almost all of the explanations just repeat the same thing without explaining it. They say endl flushes the buffer or whatever. This doesn't mean anything to me. How can I know what a buffer is? What is this so called flush? For all I understood, endl it's simply a different way of typing \\n.
https://redd.it/1ap6oel
@r_cpp
[C++20] static_[assert] is {almost} all you need!
This post is encouragement to write tests and to write tests which are executed at compile-time.
With constexpr power (especially C++20 and beyond) testing framework is not totally necessary (it may help though).
Simple lambdas, static_assert combined with assert are very powerful combination which will often offer more than actually needed.
Furthermore, especially with modules, having compile-time tests with the code will ensure single
compile-time execution upon import, which will give correctness boost for imported modules.
Additionally, a lot of memory leaks and undefined behaviors can be caught by the constexpr machinery at compile-time.
How does it work?
- It's simply based on the constexpr evaluation (therefore static_assert) and that the run-time execution (such as assert, throw, etc.)
can be executed at compile-time. Therefore if the expression compiles, it successfully pass tests, if not, it gives pretty reasonable error message (could be better).
Do I need constexpr/consteval all the things?
- Likely, but gcc also supports `-fimplicit-constexpr` which may be handy sometimes.
Is that a silver bullet?
- No, there are limitations especially with third party libraries, constexpr limitations, potentially compilation times, etc.
Example
// sections
static_assert(([test = "vectors can be sized and resized"] {
std::vector<int> v(5);
assert(v.size() == 5);
assert(v.capacity() >= 5);
[v, section = "resizing bigger changes size and capacity"] mutable {
v.resize(10);
assert(v.size() == 10);
assert(v.capacity() >= 10);
}();
[v, section = "resizing smaller changes sizes but not capacity"] mutable {
v.resize(0);
assert(v.size() == 0);
assert(v.capacity() >= 5);
}();
[v, section = "reserving bigger changes capacity but not size"] mutable {
v.reserve( 10 );
assert(v.size() == 5);
assert(v.capacity() >= 10);
}();
[v, section = "reserving smaller does not change size or capacity"] mutable {
v.reserve( 0 );
assert(v.size() == 5);
assert(v.capacity() >= 5);
}();
}(), true));
template<class T>
struct property {
// -fimplicit-constexpr or marked constexpr/consteval
void set(T value) { this->value = value; }
auto get() const { return value; }
private:
T value{};
};
// multiple types
static_assert(([test = "should set/get value"](auto... property) {
([&] {
property.set(42);
assert(property.get() == 42);
}(), ...);
}(property<int>{}, property<unsigned>{}, property<short>{}, property<long>{}), true));
// memory leaks, undefined behavior
static_assert((
[test = "new/delete"] {
auto i = new int{42};
assert(*i == 42);
delete i; // allocated storage has not been deallocated
}(),
[test = "undefined behavior"] {
const char* ptr = nullptr;
//assert(*ptr == 42); // dereferencing a nullptr
}(),
true));
Full example -> https://godbolt.org/z/xd4r3oGja
Updates -> https://twitter.com/krisjusiak/status/1757042985462600171
https://redd.it/1ap1wuo
@r_cpp
Is C++ falling behind in the race for modern language features?
I've been thinking about the current state of C++ and its evolution compared to other languages like Rust. I like C++ a lot but I can't help but wonder if C++ is falling a bit behind. Don't get me wrong, C++ has made significant improvements in recent years, introducing a lot of enhancements. However, when I look at Rust, I can't help but notice how quickly they are evolving and adopting modern programming paradigms.
It becomes evident that Rust offers a plethora of beneficial features such as pattern matching, traits, macros, better build system and a lot more. While some of these features have been proposed for inclusion in C++, the pace of adoption seems sluggish, indicating a potentially prolonged timeline. Realistically, it feels like it could take more than a decade to see significant progress in this regard. By the time c++ catches up other languages would evolved already. It feels like C++ has a huge backlog.
What are your thoughts on this?
https://redd.it/1aoykya
@r_cpp
Comparison Operator Shenanigans in C++
https://github.com/catchorg/Catch2/commit/dc51386b9fd61f99ea9c660d01867e6ad489b403
https://redd.it/1aovop4
@r_cpp
Controlling Rate-Limited Events - Implementation
https://lucisqr.substack.com/p/controlling-rate-limited-events-implementation
https://redd.it/1aorspn
@r_cpp