Questions tagged [c++]

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

Filter by
Sorted by
Tagged with
2
votes
2answers
43 views

Updated version of my first neural network in c++

I got lot of suggestions for optimizing my neural network last post I made, now I wanted to post updated version of it were I got rid of most of performance eaters, now I would really appriciate ...
0
votes
1answer
44 views

Why is this racket n queens code so inefficient?

I have the following code for the n queens problem described here: https://leetcode.com/problems/n-queens/ ...
1
vote
1answer
61 views

C++ vector bubble sort in my edition

I made a small adaptive function that sorts vector: ...
9
votes
2answers
637 views

C++ lock-free, MPMC Ring buffer in C++20

I have some performance critical inter-thread messaging code in C++. Multiple producers, one or more consumers. Profiling dozens of iterations of this messaging code over several years of development, ...
2
votes
4answers
93 views

Ring buffer for Arduino

Just wrote this small ring buffer system for an embedded device using C++98. Looking for cc, advice and bugs. Please check it out! https://github.com/Bambofy/EmbeddedRingBuffer ...
0
votes
1answer
55 views

Passing a partial application as an argument of an other function with no overhead

I am trying to find a way to pass a partial application as an argument of an other application with no overhead. I think I have find a way to do it (which might be dirty). The templated structure &...
6
votes
3answers
637 views

My first functional naive neural network in C++

I just wrote my first standard neural network with SGD gradient descent in c++, I am really interested if I have done anything wrong or inefficient, suggestions would help me a ton (There is lots of ...
3
votes
2answers
60 views

C++ ThreadGroup Implementation

Edit: An improved code based on feedback is available here. As a kind of sequel to the previous question, here is an improved version( with clarified naming ). The Idea is the same: An integer ...
0
votes
0answers
49 views

Transform inertia tensor

I am trying to translate book: Game Physics Engine Development by Ian Millington to DirectXMath and faced with the code wich transform inertia tensor. Is it right to convert code from book like that: ...
2
votes
3answers
59 views
+200

A file system watcher class for on-fly file reloading when it has been modified

I wrote a file sytem watcher class that is used to monitor file modification and then execute user-defined handler. Other file system events like moving or deleting don't need to be monitored. The ...
1
vote
0answers
45 views

C++ Improved ThreadGroup Implementation

After the amazing feedback from these questions; I have prepared a third version of the original posted code. The Idea is the same: An std::size_t variable ...
3
votes
2answers
80 views

C++11 ThreadPool implementation

A new version of this code based on the provided advice can be found here. Latest improvement is found here. I made a simple ThreadPool implementation in C++ using ...
-2
votes
1answer
47 views

MVC design pattern QT: Connecting View to the Controller

I am currently trying to implement a MVC design pattern. I prefer an approach where the model and the view are independent from each other as well as from the controller. As shown in the image. I ...
6
votes
4answers
160 views

Packing and unpacking values in a buffer

I have to deal with raw memory manipulation. For that I wrote a function which stores data one after another, and another function which reads this data and stores it into variables. More precisely: <...
5
votes
3answers
217 views

Find the mean of two values, take two

This is my generalisation of std::midpoint incorporating advice received for Find the mean of two values. As well as supporting arithmetic types and pointers, as <...
-1
votes
1answer
35 views

c++ program with 2 classes [closed]

Im making this project from few days , and now i need little help because i am struggling. The task says II. Define a student booklet class CStudBook that inherits CStudent with a member data ...
2
votes
2answers
54 views

LeetCode Reverse Nodes in k-Group

Link: https://leetcode.com/problems/reverse-nodes-in-k-group/ Problem description: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive ...
-4
votes
0answers
28 views

I m getting a error for this code. Two test cases are giving a TLE. Why? [closed]

This code is working well for majority of test cases, but there's one case where the input vector is only containing zeroes, for which it is not working out, I dry runned the code and it seemed to ...
8
votes
3answers
2k views

Checking if a username is valid

I'm learning about how to create a good and clean code. I just need to review something like that, and I really not sure how can I fix this code into a clean code. ...
6
votes
4answers
446 views

Find median of two sorted ranges

Given two sorted ranges of elements, compute a median of all the elements in O(log(n+m)) time. This solution contains only one call to std::lower_bound ...
2
votes
2answers
60 views

A simple write-once-read-many indexed based database

I started writing a cyrptocoin from scratch, and then got sidetracked writing the database portion which I eventually turned it into its own project. Data is written to the database and then retrieved ...
-1
votes
0answers
24 views

C++ | Outsource code to method [closed]

I try to improve the inner code of the if statement if (ImGui::Button("Spawn an Adder")) by outsourcing it to a method in order to be able to reuse it. ...
4
votes
2answers
104 views

Merge two pulses if they match

The function processFus() takes : Two lists of pulses (200 000 in each), as an input Two lists of pulse, empty, pulseValid and invalid. The function must fill them ...
-2
votes
0answers
33 views

How do I call a whole constructor back in one line? c++ [closed]

I'm new to C++ and wanting to find a way to return a whole constructor in one go. Rather than doing (from my example code) std::cout<<book3.pages<<book3.author<<book3.title; - is ...
-1
votes
0answers
43 views

Is my approach not correct? [closed]

Numbers of length N and value less than K I have been trying this mathematical question, from past few hours The approach I followed is simple, we can put less valued digits, at each position of given ...
5
votes
2answers
362 views

A free-standing weak_ptr equivalent to handle lifetime of non-shared callback objects

I've been finding myself wanting the following pattern recently: ...
0
votes
0answers
26 views

B+ Tree insertion [closed]

Im finding it hard to understand a specific piece of code based on B+ tree insertion this is the Source for the insertion code My doubt is in the if statement at line 143 why is two for loops used, ...
5
votes
2answers
3k views

Optimization of YUV422 to RGB

I have a stream of YUV422 encoded images coming in from a camera using Direct Show. I then run this byte array through a conversion method and return the RGB array to C# to display in a WPF app. My ...
8
votes
2answers
108 views

Find the mean of two values

A very easily stated problem that has a surprising number of gotchas - return a value that's midway between the two supplied values. Depending on the types given, we need to be aware of arithmetic ...
1
vote
1answer
48 views

Typesafe implicit wrapper for C enums

This is meant to go in a vulkan.hpp-like strongly-typed wrapper for a pure C library. A wrapped enum provides back and forth implicit conversion between itself and ...
4
votes
2answers
68 views

UTF-8 to UTF-16 using C++20 concepts and ranges

A follow-up for this previous question. I took into account previous reviews, and tried to make a simple API. I had never done anything non-trivial with C++20 concepts and ranges until now, so I am ...
0
votes
2answers
164 views

InterviewBit Problem: Stringoholics

I am trying to solve https://www.interviewbit.com/problems/stringoholics/ InterviewBit problem. Problem Statement: You are given an array A consisting of strings made up of the letters ‘a’ and ‘b’ ...
5
votes
4answers
539 views

UTF-8 to UTF-16 (char8_t string to char16_t string)

Below is an implementation of a UTF-8 string to UTF-16 string. Kind of like MultiByteToWideChar on Win32, but it's cross-platform and ...
5
votes
3answers
216 views
0
votes
2answers
71 views

Get Each Digits of Number with Using Loops in C++ [closed]

I need a program same as I wrote but using loops. (if else for etc.) . Program is that enter a number and get each digits of number like that: number is 123456. I'm beginner, I can't create the logic ...
18
votes
2answers
2k views

Chess engine for C++

Basic Description What is the program for? This is just a hobby project for me to improve at coding, not a serious one. What does the program do? It can take a chess position (not including variations ...
0
votes
2answers
46 views

cleaner for loop that accommodates direction [closed]

I have a for loop where I either increment or decrement the value of i by 1 each iteration. If start is greater than ...
0
votes
1answer
53 views

Enter the randomly displayed letter console game

The below code segments compose a simple console game where the user is prompted to enter a randomly generated letter displayed in the console. It also saves and loads user data through a .txt file. ...
2
votes
3answers
38 views

C++ evaluating an arithmetic expression in RPN format using ADT stack

Write a program that uses an ADT Stack to evaluate arithmetic expressions in RPN format. The contents of the stack should be displayed on the screen during evaluation. The allowed arithmetic operators ...
0
votes
1answer
41 views

lengthening the time it takes to access files REVISION #3

https://github.com/speedrun-program/load-extender This is the previous version: lengthening the time it takes to access files REVISION #2 To compile this, you need to download and include robin_hood.h,...
4
votes
1answer
74 views

Basic CSV Parser in C++

This was written down solely as a mean to practice basic C++ and isn't meant to serve any production purposes. Clearly, the implementation can't handle all input formats: it always expects the CSV to ...
3
votes
4answers
149 views

Multi-threaded merge sort

Below is the code for merge sort using multithreading. Will this code run for large number of inputs? Does any other part of the code need changing? ...
6
votes
3answers
4k views

Implementing a binary tree in C++ using “std::unique_ptr”

I have implemented a simple binary search tree class in C++ using std::unique_ptr objects to hold the pointers to each node. In doing this I have come across a ...
6
votes
2answers
2k views

C++ network stream

So, I'm new to socket programming. I wanted to get started learning, and start making stuff, but was really surprised to find out there was no standard C++ network library yet. I'd have to look for a ...
1
vote
1answer
67 views

Enemy damaging with regen system

Small project i made to practice my c++, im a beginner and want to know all about optimizing code. Enemy starts off with 10 HP and we can damage them for 1 HP by pressing F1, If their HP is below ...
4
votes
1answer
226 views

Token class implementation with std::variant

So I've been trying to implement a Token class in C++. At first I wanted to use a simple enum class to store the Kind of the ...
2
votes
1answer
65 views

Alpha beta pruning with memorization (transposition tables) and bitboards (5x5 cumulative tic-tac-toe)

This is my first time trying solve a game using these techniques. I've looked at pseudocode of alpha-beta pruning with transposition tables and rewritten it in c++. ...
2
votes
1answer
59 views

Computing nth Tribonacci number at compile time using C++ template metaprogramming facilities

I have this small C++ program for computing the \$n\$th Tribonacci number at compile-time. My main concern is: is it possible to get rid of the statickeyword (I had ...
4
votes
2answers
115 views

Efficiently write in a file in C++

I've made a program which reads from the console and writes it in a .txt file. This programm should write in a file with \n. <...
1
vote
1answer
40 views

CMake - Usual Build System

After wrestling with CMake I now have a fully working solution. It works, however, I completely massacred the CMake File: This is my main cmake file: ...

1
2 3 4 5
169