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
I am sorry for creating this C++ abomination. Does anyone think such code deserves to see the light of day? A fully templated Tensor class
I learned about the C++ metaprogramming and expression template stuff a few years ago but never really looked deeper into it.
Now I tried to understand how all this really works by writing a Tensor class using as much of the metaprogramming stuff as possible while still retaining something usefull.
This Tensor class got worse and worse with every hour I put into crafting it and now I have to say it is enough.
It now supports a huge amount of features and still is only one single header file.
The most notable are:
* Subtensors
And you don't even have to fear huge performance problems because the class is written in a way that lets the compiler completely skip all instantiation overhead.
Tensor<float, 4,3> t;
Tensor<float, 3> t2 = t[1];
* Expression templates
​
auto expr = t + 2 * t + 3;
t.set(expr);
For what it's worth it took me way too long to create this.
I also think that the code can maybe be written a little clearer and nicer in general.
Maybe someone of you has useful input or feedback for me 😊
Here the full code: [tensor.hpp](https://github.com/Nik4053/Templated-Cpp-Tensor/blob/master/tensorlib/tensor.hpp)
https://redd.it/1cwjn7i
@r_cpp
What version of C++ should I be using and why? I never think to check this aspect of my project, but I tried using std::format and it told me I needed to be at v20 for that feature. I don't follow the language improvements so I'm ignorant about which one I should target. Thoughts?
What version of C++ should I be using and why? I never think to check this aspect of my project, but I tried using std::format and it told me I needed to be at v20 for that feature. I don't follow the language improvements so I'm ignorant about which one I should target. Thoughts? I'm currently at ISO C++ 14 and I guess that came from a default setting.
https://redd.it/1cwkk1e
@r_cpp
New C++ Conference Videos Released This Month - May 2024 (Updated To Include Videos Released 05/13/2024 - 05/19/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
**C++Online**
05/13/2024 - 05/19/2024
* The Evolution of Functional Programming in C++ - Abel Sen - [https://youtu.be/H52B6dGgqHE](https://youtu.be/H52B6dGgqHE)
* Empowerment with the C++ Generic Programming Paradigm - Eduardo Madrid - [https://youtu.be/MGal7ixwkk4](https://youtu.be/MGal7ixwkk4)
* Cpp in the Developing World, Why It Matters - Mathew Benson - [https://youtu.be/lQ05xJEH-w4](https://youtu.be/lQ05xJEH-w4)
05/06/2024 - 05/12/2024
* Advanced SIMD C++ Algorithms in Pictures - Denis Yaroshevskiy - [https://youtu.be/uAVXVzWIIBM](https://youtu.be/uAVXVzWIIBM)
* Optimising a High Performance C++ Library: Lessons Learned - Dave Rowland - [https://youtu.be/c\_cXuL\_L0Gg](https://youtu.be/c_cXuL_L0Gg)
* Keynote: What Does It Take to Implement the C++ Standard Library? - Christopher Di Bella - [https://youtu.be/XP21DsoPaGw](https://youtu.be/XP21DsoPaGw)
04/29/2024 - 05/05/2024
* What’s New in Compiler Explorer? 2024 Update - Matt Godbolt - [https://youtu.be/28Gp3TTQYp0](https://youtu.be/28Gp3TTQYp0)
* Clean C++ Code Is Not the Norm: Why? - Sandor Dargo - [https://youtu.be/Rn6EMwPoHZk](https://youtu.be/Rn6EMwPoHZk)
**Pure Virtual C++**
05/06/2024 - 05/12/2024
* Automated Testing of Shader Code - Keith Stockdale - [https://www.youtube.com/watch?v=eqnNOhOCesc](https://www.youtube.com/watch?v=eqnNOhOCesc)
* Progress Report: Adopting Header Units in Microsoft Word - Zachary Henkel - [https://www.youtube.com/watch?v=RvliLGtaQ0c](https://www.youtube.com/watch?v=RvliLGtaQ0c)
* Templates View for Build Insights in Visual Studio - Nelson D. Troncoso - [https://www.youtube.com/watch?v=68pOEQ5YA5s](https://www.youtube.com/watch?v=68pOEQ5YA5s)
04/29/2024 - 05/05/2024
* Optimizing Game Development Workflows with Visual Studio and AI - David Li & Greg Denton - [https://www.youtube.com/watch?v=mZ4uS8\_lUzM](https://www.youtube.com/watch?v=mZ4uS8_lUzM)
* Debugging GUI Applications in a GitHub Codespace - Michael Price - [https://www.youtube.com/watch?v=ewLbgs1thSk](https://www.youtube.com/watch?v=ewLbgs1thSk)
* New Editor Features in Visual Studio for C++ Programmers - Haley Welliver and Caleb Blake - [https://www.youtube.com/watch?v=DgfSJ2\_2TGI](https://www.youtube.com/watch?v=DgfSJ2_2TGI)
* Message Handling with Boolean Implication - Ben Deane - [https://www.youtube.com/watch?v=aIPvb\_PaI1A](https://www.youtube.com/watch?v=aIPvb_PaI1A)
* Enhancing C++ development with Copilot Chat - Sinem Akinci - [https://www.youtube.com/watch?v=GpxPB6FuIAM](https://www.youtube.com/watch?v=GpxPB6FuIAM)
* I Embedded a Programming Language In Debug Information - Sy Brand - [https://www.youtube.com/watch?v=luogje8IHpM](https://www.youtube.com/watch?v=luogje8IHpM)
**CppCon**
05/06/2024 - 05/12/2024
* Lightning Talk: Is Polymorphism in C++ Really That Bad? - Paul Tsouchlos - [https://youtu.be/BujbOFNHHIY](https://youtu.be/BujbOFNHHIY)
* Lightning Talk: Program Complexity and Thermodynamics - Vadim Alexandrov - [https://youtu.be/E1\_AgDj\_2kw](https://youtu.be/E1_AgDj_2kw)
* Lightning Talk: Undefined Behavior - Toolkit to Improve Communication With Clients - Laura Kostur - [https://youtu.be/zKZiWVNenVk](https://youtu.be/zKZiWVNenVk)
* Lightning Talk: Detecting Constant Folding to Prevent Substitution Failure - Patrick Roberts - [https://youtu.be/Hoo9H9z-0VM](https://youtu.be/Hoo9H9z-0VM)
* Lightning Talk: Making Friends With CUDA Programmers (please constexpr all the things) - Vasu Agrawal - [https://youtu.be/TRQWxkRdPUI](https://youtu.be/TRQWxkRdPUI)
04/29/2024 - 05/05/2024
* Lightning Talk: Let's Fix Sparse Linear Algebra with C++. It'll Be Fun and Easy! - Benjamin Brock - [https://youtu.be/vhpj-pQTJPA](https://youtu.be/vhpj-pQTJPA)
* Lightning Talk: (Fine) Wine and MSVC: What Could Possibly Go Wrong? - Yannic Staudt - [https://youtu.be/ogrJtlaZfl4](https://youtu.be/ogrJtlaZfl4)
* Lightning
Implementing thermocouple tables
Hello, I have a project where I am using almost every type of thermocouple probe connected to a micro controller. If you don't know how thermocouples work, essentially it's a simple device of 2 wires being welded together, and at specific temperatures they output a known voltage.
This is commonly used for temperature measurement, as you can measure the voltage to get temperature (simplified). In order to know the temperature based off of the voltage you must have the table that corresponds the voltage and temperature. Since this table is just temperature to voltage, its 2 columns. However the tables sometimes have 1500+ rows.To add to the pain, I haven't been able to find a text file of these tables, only PDF formats.
What would be the fastest way to implement these tables into memory and search through one column of data to find the corresponding data point. I was thinking a 2D array using binary search (since the tables are already sorted).
https://redd.it/1cw8zkm
@r_cpp
I started studying software engineering about 4 months ago and so far we’ve covered c++ and currently on MySQL.
I want to be a game developer therefore I’m trying my best to master c++ but due to how quick my course is I really don’t get enough time to do much c++ practices, I’m much focused on being able to pass the other programming languages so I could secure my software engineering degree.
Do you guys think I should put in more effort and focus into c++ or I should just chill till I’m done with my course.
I need an advice please
https://redd.it/1cw3jli
@r_cpp
Invitation to a new software development tools subreddit
Howdy,
For those looking for new and better software development tools (in the fields of: embedded, gaming, PC), we invite you to visit the company's subreddit:
/r/WarmZero
Greetings!
Warm Zero
https://redd.it/1cvzi3m
@r_cpp
Aiuto per un programma!!
Ho bisogno di ordinare in ordine alfabetico stringe disordinate dentro un Array, in top down, ragazzi sono principiante, e davvero non riesco a trovare una soluzione, grazie.
https://redd.it/1cvwgjr
@r_cpp
is my code is optimized because it takes time second to execute
hello everyone,
am sorry if my question is typed and I am new to cpp. so I am making project for class and in my code I want to apply blur filter on aa given image, when I look at gprof it shows me the calculate average function is being called the same amount number of pixels as the given image is there is a way I can make my code more optimized?
here is my code.
thanks for everyone in advance.
pngbytep calculateaverage(pngbytep row, int x, int y, int channels) {
int sumRed = 0, sumGreen = 0, sumBlue = 0;
int neighborCount = 0;
for (int dy = -1; dy <= 1; dy++) {
int ny = y + dy;
if (ny >= 0 && ny < height) {
for (int dx = -1; dx <= 1; dx++) {
int nx = x + dx;
if (nx >= 0 && nx < width) {
pngbytep neighbor = &(rowpointers[ny][nx * channels]);
sumRed += neighbor[0];
sumGreen += neighbor[1];
sumBlue += neighbor[2];
neighborCount++;
}
}
}
}
pngbytep result = (pngbytep)malloc(channels * sizeof(pngbyte));
if (neighborCount > 0) {
result0 = (pngbyte)(sumRed / neighborCount);
result[1] = (pngbyte)(sumGreen / neighborCount);
result2 = (pngbyte)(sumBlue / neighborCount);
} else {
memcpy(result, &(row[x * channels]), channels * sizeof(pngbyte));
}
return result;
}
void processpngfile() {
for (int y = 0; y < height; y++) {
pngbytep row = rowpointersy;
for (int x = 0; x < width; x++) {
pngbytep px = &(row[x * 4]);
pngbytep averagecolor = calculateaverage(row, x, y, 4);
px0 = averagecolor[0]; // Update red channel
px[1] = averagecolor1; // Update green channel
px2 = averagecolor[2]; // Update blue channel
// free(calculategrayscale);
free(averagecolor); // Free memory allocated in calculateaverage
}
}
}
https://redd.it/1cvq4qx
@r_cpp
Learning C++ Day 1
I am currently in high school wishing to pursue a career in technology and space technology. Thus as a recommendation from my father who is an excellent engineer, I will begin my journey of learning C++. I am currently using a course provided by Cisco Netacad. Pls give me some advice on how to enhance my learning and some basic projects I can do. Hopefully I will be posting everyday giving updates!
https://redd.it/1cvmkrp
@r_cpp
std::uniqueptr or rvalue reference as a parameter?
AFAIK, both of the following examples implement move semantics correctly and avoid copies, but which do you prefer and why?
class Node {
std::vector<std::uniqueptr<Node>> children;
public:
// Example 1: std::uniqueptr as a parameter
void addChild(std::uniqueptr<Node> childNode) {
children.pushback(std::move(childNode));
}
// usage:
// someNode->addChild(std::uniqueptr<Node>(someOtherNode));
// Example 2: rvalue reference as a paramter
void addChild(Node&& childNode) {
children.pushback(std::makeunique<Node>(std::move(childNode)));
}}
// usage:
// someNode->addChild(std::move(someOtherNode))
}
https://redd.it/1cvb92d
@r_cpp
Better way to self teach myself C++
Hello, so I've been using learncpp.com along with visual code community 2022 to learn. The way I would teach myself is to make notes and pratice writing the code presented from scratch without looking at the code. I would keep doing that until I dig it deep into my memory.
The issue i'm having is that I keep thinking and worrying myself that I will forget everything i've learned and struggling to keep the basic facts in my head such as "What is a variable?" "How do functions work?" and I feel like i'm missing important information.
Is there any better way to do this?
https://redd.it/1cv9o21
@r_cpp
Any way to split constexpr function declaration/prototypes from their definition in separate files?
I was working on a personal project yesterday in C++23 and was running into a linker (ld) error stating that my constexpr had undefined symbols. After some digging, I realized that constexpr objects are implicitly inline and must have their definitions visible at every compiler stage.
That being said, I had to move the function definitions from their .cpp source file into their header file, but I was wondering if there was still a way to keep the definition in a separate file (while preserving their constexpr modifier)?
https://redd.it/1cv4x4f
@r_cpp
Are we missing a Ranges customization point?
https://brevzin.github.io/c++/2024/05/18/range-customization/
https://redd.it/1cv13or
@r_cpp
Is there a platform agnostic critical section for use in C++?
My project is currently using mutexes for a singleton pattern initialization. Is it now true that if I use a static local variable, a boolean that tracks if initialization has occurred globally, that I no longer need to use a mutex? If this is not true, is there something faster than a mutex that is also platform independent? I'm looking at the critical sections but they are Win32. Is what I am doing fast enough? I'm always trying to shave off runtime and get more performance.
https://redd.it/1cuyjl6
@r_cpp
How bad is the Dinkumware std implementation?
Since the beginning of the year I have had write C++ in an environment that unfortunately uses the the Dinkumware implementation of the std lib: C++Builder 11. During this time I’ve been bitten by a plethora of in your face bugs that have forced me to invest a bunch of time into understanding and then circumventing the issues. To name just a few:
* std::optional<bool> doesn’t compile
* std::optional<NonDefaultConstructible> doesn’t compile
* std::visit is broken
* std::variant::operator = will silently mess things up by setting the wrong index
* std::unordered_set::extract will return a handle that when destroyed decrements the number of elements in the collection. So one extract causes two sides decrements.
Fortunately, the last version of C++ Builder seems to be moving away from Dinkumware, but until I upgrade, is anyone here aware of a broader list of Dinkumware bugs? Is Dinkumware such a poor quality implementation? Has it always been like that?
https://redd.it/1cuua7c
@r_cpp
I need an explanation about std::future and std::sharedfuture
I’m going over my concurrency notes, and I understand the *technical* difference between std::future and std::sharedfuture, in that multiple threads can see the result of one particular future by copying it….
But something about it seems unclear. I get that using the regular future would throw the exception that the future is invalid if multiple threads try to access it’s result, but as I’m still a beginner, I just don’t have a good program example of where someone would use it. Can any experienced programmers tell me a bit about where you might implement std::sharedfuture in your program? Like why you would use it? especially since cppreference says that access to the same shared state from multiple threads is safe if each thread does it “through its own copy” of a sharedfuture object (keyword copy sounds like something a program shouldn’t do)
https://redd.it/1cwlbc5
@r_cpp
Talk: Know Your Audience: Who’s Building Your C++ Code - Chris Thrasher - [https://youtu.be/xSrEHZ6Sgfg](https://youtu.be/xSrEHZ6Sgfg)
* Lightning Talk: Writing a Better std::move - Jonathan Müller - [https://youtu.be/hvnl6T2MnUk](https://youtu.be/hvnl6T2MnUk)
* Lightning Talk: Enhancing C++ exceptions with Context - Shachar Shemesh - [https://youtu.be/LvzmAJ9\_rDk](https://youtu.be/LvzmAJ9_rDk)
All of these talks can also be accessed at [https://cppcon.programmingarchive.com](https://cppcon.programmingarchive.com/) where you can also find information on how to get early access to the rest of the CppCon 2023 lightning talks.
**Audio Developer Conference**
05/13/2024 - 05/20/2024
* NO MORE CODE: New Graphical Programming Language for Audio Research and Developers - ChangHun Sung - [https://youtu.be/uYUblZhbG1A](https://youtu.be/uYUblZhbG1A)
* PANEL: Audio Tech Ecosystem in India: Opportunities and Challenges - [https://youtu.be/ivYVCgzDzYk](https://youtu.be/ivYVCgzDzYk)
* Recent Updates to MIDI 2.0 and the newest MIDI 2.0 APIs in the Apple, Google, Linux and Microsoft operating systems - Florian Bömers - [https://youtu.be/EKJbUKx\_WIg](https://youtu.be/EKJbUKx_WIg)
05/06/2024 - 05/12/2024
* Accelerated Audio Computing: From Problem to Solution - Alexander Talashov & Alexander Prokopchuk - [https://youtu.be/X9TN9la0Q0Y](https://youtu.be/X9TN9la0Q0Y)
* Virtual Studio Production Tools With AI Driven Personalized Spatial Audio for Immersive Mixing - Dr. Kaushik Sunder & Krishnan Subramanian - [https://youtu.be/Uhf4XUQwcLk](https://youtu.be/Uhf4XUQwcLk)
* Workshop: An Introduction to Inclusive Design of Audio Products - Accessibility Panel - [https://youtu.be/-iVDiV1Iwio](https://youtu.be/-iVDiV1Iwio)
04/29/2024 - 05/05/2024
* Legacy Code for the Learning Audio Engineer: Examples In C++ - José Díaz Rohena - [https://youtu.be/b9z8a2z4ZP4](https://youtu.be/b9z8a2z4ZP4)
* AI Generated Voices: Towards Emotive Speech Synthesis - Vibhor Saran - [https://youtu.be/5FoI9JPNbo8](https://youtu.be/5FoI9JPNbo8)
* Audio Technology Industry Standards - the Agony and the Ecstasy - Angus Hewlett - [https://youtu.be/wVxS9Rv1y88](https://youtu.be/wVxS9Rv1y88)
https://redd.it/1cwinqy
@r_cpp
Taking up C++ again, are C++20 specifics etc. necessary for coding comps and junior interviews?
Hello,
I used to have a strong capability for solving algorithmic problems using C++, but I haven't practiced for a year as I have been working more with Python on ML topics. Starting in September, I will be pursuing a CS MSc. I'm no longer interested in the Data Science path, but rather in software development, particularly algorithms (this was the most stimulating part of my bachelor's education) or trading (I had a Finance minor). I want to regain my proficiency.
Currently, I'm reading "C++ Crash Course: A Fast-Paced Introduction" to refresh my knowledge while also studying introductory material about derivatives. After that, I plan to dive into Leetcode and "Cracking the Coding Interview." I also have "Algorithmic Trading" by Ernest Chan in mind for when I get back to a good level of coding.
However, I keep wondering: how deeply should I delve into C++, especially regarding the new versions? Do you have any tips or reading material you think I should check out to achieve my goals? I would be grateful for any help.
https://redd.it/1cwacsu
@r_cpp
How to create a installer for cmake project over 2 gb
Hey trying to create a installer tried cpack + NSIS but it's failing as it can't handle installer over 2 GBs. Is there any alternative which is fairly easy to use. How do you guys create them?
https://redd.it/1cw5lr7
@r_cpp
(Question from a rookie) Why is learncpp exploring every possible way to do functions when I can just do it a way I like?
I am self teaching myself C++ from learncpp.com. I am on chapter 2 which is where it goes over functions and their different types.
Once thing i've notices is that it keeps going over the same code it went over before and modifying it to find out different ways you can go about writing the code.
For example: Void and Int functions.
I'm quite familiar with int functions but quite confused on void because it doesn't explain what it is very well. In section 2.4 it goes off imediatley showing a code I practised alot and understand how it works but then soon shows how we can make it work with the void function.
The code (Int):
#include <iostream>
int getValueFromUser()
{
std::cout << "Enter an integer";
int input;
std::cin >> input;
return input;
}
int main()
{
int num{ getValueFromUser() };
std::cout << num << " Doubled is: " << num 2 << '\n';
return 0;
________________________
Pretty straightforward right? You're making the code prompt you to enter an integer and then it will double the the number.
Example:
4 Doubled is: 8
But then the tutorial brought that one back again and decided to make it work with the void function.
#include <iostream>
int getValueFromUser()
{
std::cout << "Enter an integer";
int input;
std::cin >> input;
return input;
}
void printDouble(int value)
{
std::cout << value << " Doubled is: " << value 2 << '\n'
}
int main()
{
int num { getValueFromUser() };
printDouble(num);
return 0;
}
My biggest annoyance here is why are you trying to make me do 50 extra steps to a code I already got good at, no wonder i'm confused on how your explaining things.
Any better tutorial so I don't have to deal with this?
https://redd.it/1cw0vxp
@r_cpp
Resources for learning to write C++ programs
Can anyone recommend some learning resources for writing and compiling actual executable software? I have some c++ and programming experience but it is limited to scripting and programming Arduino. In college I took intro to c++ and a computational fluid dynamics course in which I wrote c++ scripts to solve and model differential equations. I am a mechanical engineer so I have also used matlab extensively for work, programmed robots in a language similar to python, lua for writing touchOSC scripts, and VBA for automating excel. It’s quite a hodgepodge of programming skill sets and again all individual scripts of varying complexity.
I am now working on a project developing software for a multitrack looper for making music. I am currently using an open source software looping program but would like to write my own.
This would be a “real” program, something with a rudimentary UI and multiple functions that can be compiled and run as an executable. I am having trouble figuring out how to make the jump from simple scripts to actual software development. Can you point me in the direction of some learning resources to move from this sort of “beginner” level programming to something more intermediate level?
https://redd.it/1cvyirq
@r_cpp
Quantum computing using c++
Can anyone suggest me some resources(books,videos , tutorial) which does quantum computing using c++
https://redd.it/1cvul76
@r_cpp
Using C++ as a Scripting Language, part 13
fwsgonzo/using-c-as-a-scripting-language-part-13-cb99c38205d9" rel="nofollow">https://medium.com/@fwsgonzo/using-c-as-a-scripting-language-part-13-cb99c38205d9
https://redd.it/1cvny23
@r_cpp
Why the penultimate field of class is always initialized with 1?
#include <iostream>
using namespace std;
class Date {
// TODO why penultimate one always init with 1 by default?
int d, y, m, x;
public:
Date(){}
void show() {cout << y << "-" << m << "-" << d << endl;}
};
int main() {
Date d;
d.show();
return 0;
}
I tried swap positions, add extra fields, and could be sure it's always the penultimate field get a certain value, 1.
I reckon this behavior is implementation-defined, just curious.
Can you guys replicate it on your computer?
>Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
https://redd.it/1cvlvgw
@r_cpp
Reflection in C++26: the renaissance of C++
https://youtu.be/vRda0mGYg_A?si=CSzENClTssKtK1U8
https://redd.it/1cvahnr
@r_cpp
Good Place To Find Collaborators
Hey! I'm looking to make a C++ game engine/framework to hopefully make a game at some point.
I've been using C++ for about a year at this point and have mostly specialized in rendering with OpenGL. I haven't fully grasped all concepts around memory and memory management (I know what a pointer is and that is really it). I'm also considering C for that same reason.
I'm looking for a place where I can find collaborators that would help me build a engine/framework, and help me with all the memory stuff. I already posted on a discord server about game dev, but most people seem to be unity programmers or things other than programming.
Thanks in Advance!
https://redd.it/1cv5jrg
@r_cpp
A C++ type list, but how and why
https://a4z.gitlab.io/blog/2024/05/18/cpp-typelist.html
https://redd.it/1cv2pv1
@r_cpp
CppCast: Rust <=> C++
https://cppcast.com/rust_lt_eq_gt_cpp/
https://redd.it/1cv0v6n
@r_cpp
What's the error here (That took me half an hour to see)
// a and b are integers
if (a - b > vec.size()) {
foo();
}
https://redd.it/1cuw1ce
@r_cpp
Why can't I find the injected name of a templated class's templated base class? - The Old New Thing
https://devblogs.microsoft.com/oldnewthing/20240517-00/?p=109774
https://redd.it/1cutf3q
@r_cpp