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

[Beginner Friendly] Game Engine Series: Follow Along as We Build from Scratch!
https://www.youtube.com/embed/f9MCMZcCeDI

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

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

C++ - Reddit

MSVC not optimizing out function aliases

I want to wrap some code around function aliases, but noticed that inlined functions are not inlined while using them in msvc. see example in godbolt

Basically unless I call the function directly, its not inlined. GCC on the other hand does a great job inlining the function.

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

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

C++ - Reddit

Launch: program "" does not exist

Just started with c++ and visual studio and came across this error. I've been trying to solve it for a few days at this point, but without any success. I would greatly appreciate any help, thanks in advance!

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

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

C++ - Reddit

Bengt Gustafsson: Implicit conversion functions - standardizing a small feature (and a surprising end)
https://youtu.be/bb9hPtuVaTU

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

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

C++ - Reddit

I need a single-consumer, multi-ad-hoc-producer queue

Implementations like the moody-camel queue (which seems really great) are, I think, not the right fit because they rely on a token that each producer requests at start of his operation, where the operation is an ongoing, spaced out in time, production of elements.

My use case is somewhat different: my producers don't have an identity or lifetime but are just short-lived threads with a one-off task of delivering their data packet received from the network towards a data concentrator. (Order is very relaxed, in this respect the moody-camel would be ok for me)

From what I understand reading the doc page, by my use case, the user-generated per-producer token (which needs to be unique I suppose) throws me back to the same problem like that from a shared lock in a classical approach, ie. producers fighting for access of the single source token generator because each data reception necessitates a new token.

Am I totally wrong and don't see the forest for the trees? Is my problem similar to many network processing problems, and if so, how is it solved usually? TIA to all who care to answer.

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

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

C++ - Reddit

The C++ Standards Committee and the standard library

While perusing through the latest experimental C++ additions and I ask myself the same question ive been asking myself every time a new standard comes out: "Why are some language features pushed into the standard library instead of becoming parts of the language itself"

There seems to be a preference to put as much as possible in the std namespace in the form of functions. Some example features that im not entirely sure of why they are not language features:
std::meta::members_of
std::forward
std::size_t
is_integral_v, convertible_to, same_as etc.
std::function
std::initializer_list<int> in constructors

Now im not saying the C++ committee is wrong. This is not a criticism. I just dont really get their rational for why some features like coroutines become part of the language, and other features like std::forward do not become part of the language. I tried googling it, but I could not find anything substantive.

Interstingly atomic blocks has not been pushed into the std
https://en.cppreference.com/w/cpp/language/transactional\_memory#Atomic\_blocks



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

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

C++ - Reddit

tanuki Yet another take on type erasure

Hello reddit!


As a long-time enthusiast of type-erasure-based runtime polymorphism, I set out a few months ago to write a little library/toolkit with the goal of minimising the amount of boilerplate code necessary to implement type erasure in C++.


The result is a little, self-contained, single-header, no-dependencies C++20/23 library called tanuki and available as an open-source project on github:


https://github.com/bluescarni/tanuki


I am about 75% happy about the final result - enough to use the library in my personal projects (replacing several bespoke solutions developed over the years) and at work. Still, I think C++26 reflection (+ the ability to codegen member functions) is needed to make the next leap in usability for this type of library.


The main idea of the library is to blend traditional OO programming with C++20 concepts. Standard OO constructs are used to define and implement interfaces, C++20 concepts are used to select implementations based on the properties of the types that are being type-erased.


The library supports both value and pointer interface/semantics, it implements a highly configurable small object optimisation, it supports type-erasing references, composite interfaces, the ability to type-erase existing OO interfaces, and it also offers (optional) support for Boost.serialisation. API docs and tutorials are available here:


https://bluescarni.github.io/tanuki


Here is an advanced tutorial exploring how to implement a sort of hybrid between std::function/std::moveonlyfunction/std::functionref`` in tanuki:


https://bluescarni.github.io/tanuki/stdfunction.html


I am sharing the library in the hope it can be useful to other people, and of course I would be glad to hear feedback/criticism/etc. :)


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

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

C++ - Reddit

Why are the committee aiming so high with reflection/enum-to-string?

It seems to me most people, including myself, only want the equivalent of std::get<N> for any class.

Yet it seems reflection is postponed because the proposals aim's for reflexpr expressions, or even another meta language with new \^ operator.

I really don't understand why we can't have a simple std::get<N> equivalent reflection right now, which suits 99% of the use cases, and let the meta language/reflexpr stuff arrive when ready.

Same goes for enum-to-string, we don't have to take the long route, simply add two magic function (std::enum_to_string() and std::enum_list<E>() -> std::span<>).






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

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

C++ - Reddit

cpp basics

need some help solving a programming basics question.

(I can send screenshots on discord or whatever of the problem)

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

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

C++ - Reddit

Implementation of get_n from variadic type sequence that doesn't use recursive inheritance

I am writing a template meta programming library and one of the goals is to retain fast compilation speeds by avoiding recursive template instantiation.

For anyone that has written a library like this, type sequence is one of the first things to make, and its associated meta-functions.

Researching "common" techniques to write one of the fundamental "get n" metafunction you will probably find that it typically uses std::disjunction, where std::index\_sequence is used to create an "index" for each type in the sequence, and the index is compared against N, creating a true/false value with is bundled with the Nth type into each type in the disjunction sequence.

However, std::disjunction uses short-circuiting recursive inheritance, so how can this be done without using std::disjunction?

Working on this I developed a technique which seems promising which I haven't seen used elsewhere - the basis of the technique is to once again to use multiple inheritance of a leaf type, however, the interesting part (imo) is using the index to create requires clauses for each static member function, so when these functions are brought into scope in the derived class, the index can be used in the overload resolution solving the ambiguity, and avoiding the need for recursive inheritance (and fold expansion as well):


e.g.

namespace details
{

template<std::size_t I, typename T>
struct get_n_element_impl
{
template<std::size_t N>
requires(N == I)
static constexpr T get();
};

template<typename T>
struct get_n_impl;

template<std::size_t... Is, typename... Ts>
struct get_n_impl<type_sequence<pair_vt<Is, Ts>...>> : private get_n_element_impl<Is, Ts>...
{
using get_n_element_impl<Is, Ts>::get...;
};

}

template<typename T, std::size_t N>
using get_n = decltype(details::get_n_impl<T>::template get<N>());

To test, I had this example:

int main()
{
using seq1 = make_indexed_sequence<
type_sequence<
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int,

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

C++ - Reddit

Making an AI with C++

Hello, i want to create a program in C++, basically just a tictactoe game, but i want to create an AI that plays with me, i don't want random moves from the AI, i want it to be somewhat intelligent, how can i do it? i just want to know what stuff is it that i have to learn inorder to make this, i just want a simple list of things that i need to learn in sequence to pull this off. [also it would be helpful if you can give me some resources from where to learn that\]

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

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

C++ - Reddit

Making an AI with C++

Hello, i want to create a program in C++, basically just a tictactoe game, but i want to create an AI that plays with me, i don't want random moves from the AI, i want it to be somewhat intelligent, how can i do it? i just want to know what stuff is it that i have to learn inorder to make this, i just want a simple list of things that i need to learn in sequence to pull this off. [also it would be helpful if you can give me some resources from where to learn that\]

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

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

C++ - Reddit

Is using different base classes with the same interface UB?

Names shortened for simplicity.

We have an abstract base class B that gets used with several other classes and two procucts. Unfortunately the two products have separate copies of the same headers.

The code that we used to have was

Class App1 : public B ...

Then somewhere in app2

B* b = getApp1Obj(...).

One of my colleagues changed this to decouple the two products. So we now have

// app 1 class B same interface as app2 class Bold

Class App1 : public B ...

// app 2

Bold* b = getApp1Obj(...).

// other uses of class B wich is not the same as app 1 B

class B in app 2 can now evolve separately from class B in app 1. We have any linking issues because the app 1 shared library is loaded with dlopen and it only exposes the getApp1Obj symbol.

This loks like a bad code smell to me. But is it UB or similar?

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

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

C++ - Reddit

CMake, VS 2022, Win32 - Basic Project Setup
thomas-a-mathew/visual-studio-2022-cmake-win32-api-5be027ead9da" rel="nofollow">https://medium.com/@thomas-a-mathew/visual-studio-2022-cmake-win32-api-5be027ead9da

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

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

C++ - Reddit

How has your experience with interviews been lately?

Hi everyone!

I'm trying to understand how C++-based role interviews differ from those for other software engineering positions. Do you solve LeetCode-style questions for these interviews (excluding FAANG companies)? What kinds of questions typically come up during these interviews?

Also, with hiring being slower this year, do you think the difficulty level of interviews has changed due to fewer positions being available? Are companies being more selective with candidates?

Please specify the location (e.g., US, EU) as interview experiences can differ significantly by region.

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

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

C++ - Reddit

C++ Linux Server development on Windows

Hi, I want to mess around with creating a server in C++ (using CROW) on my main windows PC, I want to deploy and test the server on my Raspberry Pi running as a headless server. Previously I was writing the code in visual studio, pushing to git and then I pull and compile on my Pi. I want to keep developing on my PC, what are better workflows for this?

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

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

C++ - Reddit

C++ JSON library comparison

Posted this library about a week ago.

Because of feedback here I have made the library a lot easier to build for others (but it is 24 other projects pulled together so can probably get better).

Added two new libraries:

[simdjson](https://github.com/simdjson/simdjson)
boostjson

Hopefully a couple more this week.


https://github.com/Loki-Astari/JsonBenchmark



Conformance mac linux
Performance mac linux



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

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

C++ - Reddit

Reader Q&A: What’s the best way to pass an istream parameter?
https://herbsutter.com/2024/09/03/reader-qa-whats-the-best-way-to-pass-an-istream-parameter/

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

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

C++ - Reddit

init_from - init one struct from another

Hey! :)

I over-engineered a solution to initialize the members of a struct (could be references or values) from the members of another struct. Matching is done only based on the type.

Example:

https://gcc.godbolt.org/z/6MhrM956a

struct a {int& i_; float& j_; int& k_;};  
struct b {double z_; std::unique_ptr<float> x_; int y_;};


So if I want to initialize a from b here:

- a.i_ should reference b.y_
- a.j_ should reference *b.x_ (note the deref)
- a.k_ should reference b.y_ (again)

Use case (for me) was that we have a lot of HTTP handler structs all referencing a mostly small subset of a big data struct that holds the applications data. This utility does the job of initializing each member of each of those handlers.

Here is the "full" version we're using in prod. It has null checks and returns std::nullopt if one of the referenced members was set to null (in this case, the HTTP handler won't be instantiated and 404 will be returned for this route).

Of course manually doing this is still possible.. :-)

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

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

C++ - Reddit

_Ret_maybenull_ in SAL/VisualStudio not working as expected

Hello! I'm working on a Visual Studio project, and trying to learn SAL (sal.h). I started using `_Ret_maybenull_` to force callers of a function to check returned pointers for null. But it doesn't seem to work in all scenarios, as shown below:

struct S {
    int method() noexcept { return 0; }
};

_Ret_maybenull_ S* getStructPtr() noexcept { return nullptr; }
_Ret_maybenull_ int* getIntPtr() noexcept { return nullptr; }

int foo() noexcept {
    return getStructPtr()->method(); // no warning :(
}

int bar() noexcept {
    return *getIntPtr(); // warning C6011: Dereferencing NULL pointer 'getIntPtr()'
}

Godbolt link: [https://godbolt.org/z/Y7f7TTjrM](https://godbolt.org/z/Y7f7TTjrM)

Any idea what I am doing wrong? I want to get the warning in both `foo` and `bar`. Maybe I've just hit a limitation of the VS code analysis tool.

I also tried `_Must_inspect_result_`. It is not exactly the same... but it forces the caller to check the returned thing. The issue with that one is that it REALLY forces you to check.

_Must_inspect_result_ int* foo();

int* x = foo();
int* y = foo();
if(!x || !y) return;
use(x);
use(y); // warning: y is not inspected in all code paths

I just want to force the caller to check for null. Is that too much to ask?

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

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

C++ - Reddit

What are decent sources about good practices in C++?

Hi guys
recently I've decided to write something in C++. I'm not very experienced in C++ (but I work as a .NET dev), although I know basic concepts like pointers etc. Can you recommend me some good sources where can I find up-to-date info about good practices in modern C++ standards? Many times I'm stuck on the problem "What's the best way of doing xyz?" For example, I would like to define 2d array of integers as a member of a class and what is the best way of doing this? Should I define it as a int**? Should I use a vector? When I search for answers on stack or reddit usually I find many conflicting answers. Additionally, many replies seem to be obsolete because they were written at the time of older standards and because of my lack of experience in cpp I'm unable to differentiate what is obsolete and what is good.

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

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

C++ - Reddit

mini docs for Vscode C++?

Hi, sorry I just started learn C++, is there a something can do more information in Vscode like this:

https://i.imgur.com/IEmDpte.png


my C++ setup looks like this , just no information whatever, even when I do "Ctrl+click" on any word I just see wired file with No english word.


https://i.imgur.com/HLehpD8.png



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

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

C++ - Reddit

Performance comparison of logging libraries
https://github.com/odygrd/quill?tab=readme-ov-file#-performance

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

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

C++ - Reddit

double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int,
int, double, int, int, double, int, int, double, int, int, double, int
>
>;

constexpr auto size = seq1::size; //396
auto val = get_n<seq1, 103>{};
auto val1 = get_n<seq1, 23>{};
auto val2 = get_n<seq1, 346>{};
auto val3 = get_n<seq1, 21>{};
auto val4 = get_n<seq1, 64>{};
auto val5 = get_n<seq1, 12>{};
auto val6 = get_n<seq1, 11>{};

return size + val + val1 + val2 + val3 + val4 + val5 + val6;
}

The above compiles pretty much instantly in debug mode and outputs 140 (396 - 256)


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

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

C++ - Reddit

Announcing the Proxy 3 Library for Dynamic Polymorphism - C++ Team Blog
https://devblogs.microsoft.com/cppblog/announcing-the-proxy-3-library-for-dynamic-polymorphism/

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

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

C++ - Reddit

Is it an implementation bug or specification defect that neither the MSVC STL nor libc++ export functions in <cstring> with module std.compat?

Not much text to put here—it is impossible to use only import std; or import std.compat; under MSVC 19.40 (VS 2022 17.11) or Clang 18.1.8 and compile the following code (of course, with the necessary CMake 3.30 scaffolding to set up import std;):

import std;
import std.compat;
// #include <cstring> // uncomment to compile

auto main() -> int
{
std::println("Length of \"Hello World!\": {}", strnlen("Hello World!", 20));
}

The <cstring> (or <string.h> if you fancy) header needs to be explicitly included to resolve the missing declaration compiler error, and compile the above. Given what cppreference says.) about std.compat (emphasis mine):

> The C++ standard library provides the following C++ library modules:

> The named module std exports declarations in namespace std that are provided by the importable C++ library headers (e.g. std::rotr from <bit>) and the C++ headers for C library facilities (e.g. std::puts from <cstdio>). It additionally exports declarations in the global namespace for the storage allocation and deallocation functions that are provided by <new> (e.g. ::operator new).
>
> The named module std.compat exports the same declarations as the named module std, and additionally exports declarations in the global namespace corresponding to the declarations in namespace std that are provided by the C++ headers for C library facilities (e.g. ::fclose).

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

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

C++ - Reddit

New C++ Conference Videos Released This Month - September 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

ACCU Conference

2024-08-26 - 2024-09-01

Think Parallel - Bryce Adelstein Lelbach - [https://youtu.be/VSDmkwHWpfA](https://youtu.be/VSDmkwHWpfA)
Testing C++ Templates: Investigating Tests for C++ Templates using Adversarial Methods - Peter Hrenka - https://youtu.be/U-nwq\_f\_koo
Data Oriented Design and Entity Component System Explained - Mathieu Ropert - [https://youtu.be/xm4AQj5PHT4](https://youtu.be/xm4AQj5PHT4)

C++Now

2024-08-26 - 2024-09-01

Dependency Injection in C++ - A Practical Guide - Peter Muldoon - https://youtu.be/kCYo2gJ3Y38
Functional C++ - Gašper Ažman - [https://youtu.be/bHxvfwTnJhg](https://youtu.be/bHxvfwTnJhg)
Keynote: C++ Painkillers for C++ Developers - The Evolution of C++ Tooling - Anastasia Kazakova - https://youtu.be/sxWe9KzYQSI



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

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

C++ - Reddit

Is it okay for me to do too much pointer arithmetic in C++?

Hi, as titled.

I have been writing a synthesizer, aims to making it performs like a live coding platform, where users can create synth unit and hook them together in any way they like, during runtime.

Hooking them together means that one unit's output (or parameter) is rewriting another unit's parameter, e.g. a Amp modulating synth is one Sine wave function where another Sine wave is its amplitude.

The only solution okay to me I can come up now is that I make assumption that every units' parameter is just a float, put every parameter in a shared memory pool like a huge array of floats (made up from smaller array, each pointed by one ugen), and perform pointer arithmatic for each read or write. Also I will have the user to remember that the index of each parameter, like for an OSC (sine wave oscillator), the first is output, the second is frequency and so on.

There exists other ugens like ADSR envelope, where three 2d vectors are required, proposing 6 or more floats if I have to go with my solution

I am doing this so that I don't need to write a million of Getters and Setters. Furthermore, putting everything on heap allows it to be live coding, where user don't need to recompile the whole program in changing their synthesizer.

Is this the best way for doing this?

Find the source code for it here Roventta/Syntheloper at QPCG-1 (github.com), the question mainly lives around ugen.h, QPBusChannelGrain.h, and osc.h.

Thanks in advance, feel free to gas light my code.

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

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

C++ - Reddit

C++ Show and Tell - September 2024

Use this thread to share anything you've written in C++. This includes:

* a tool you've written
* a game you've been working on
* your first non-trivial C++ program

The rules of this thread are very straight forward:

* The project must involve C++ in some way.
* It must be something you (alone or with others) have done.
* Please share a link, if applicable.
* Please post images, if applicable.

If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.

Last month's thread: https://www.reddit.com/r/cpp/comments/1eiclin/c_show_and_tell_august_2024/

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

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

C++ - Reddit

How I Learned to Get By with C++ Packaging: A 5-Minute CMake Survival Guide
https://journal.hexmos.com/cmake-survial-guide/

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

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