About C++ and contributing to LLVM
Hey everyone! How are you doing? I have some experience with C++ and I'd like to contribute to an open source project. Since I also enjoy working with compilers, I thought that contributing to LLVM would be a nice idea. However, I've heard in another sub that the maintainers don't accept PRs from hobbists. Only from folks that are working in the industry. I'd like to know if this is indeed true. And if not, if some of you guys has already contributed to it, what was it like? What would recomend for someone that is trying to get into it?
Thanks in advance.
https://redd.it/1edobsd
@r_cpp
Experimental reimplementations of a few Win32 API functions w/ std::wstring_view as argument instead of LPCWSTR
https://github.com/tringi/win32-wstring_view
https://redd.it/1edivqg
@r_cpp
Question about C++ linking - video from TheCherno
Hello everyone.
So I'm learning about linking, and Cherno talks about something at 7:15 in the video - https://www.youtube.com/watch?v=H4s55GgAg0I&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=7
He's getting a linking error even though he commented out a function in main, and you'd think he wouldn't get an error because the code causing this error is useless, it doesn't get called anyway, and the compiler would just remove it so by the time it comes to the linking stage, that code won't be there to cause a problem.
He explains that even though we don't use the Multiply function in this file, we "could" technically use it in another file.
My question is: Even if we could use the Multiply function in another file, isn't the main function what's most important, because that's what gets executed? Meaning that, if it isn't in the main function, what's the point in considering whether we could use the Multiply function in another file?
I'd appreciate any clarification on this. Maybe I'm asking the wrong question, but this part confused me a bit.
https://redd.it/1ede1s9
@r_cpp
this rope class WILL NOT copy a huge buffer , but instead, it divides the buffer into 2 sub buffers and adds a 3rd modification string in the middle of the 2 sub buffers to ensure a copy less operation.
Note: the has_null flag is mostly off , for shared substrings, but mostly on for owning heap strings.
Note : the sso length is stored by a combination of Facebook's null and length technique , and the has null flag with if false , indicates a full sso buffer.
Tl;dr:
I saw all of the string optimization techniques and could not resist the temptation of making a plan for using them all in a single class
The theoretical completed implementation should provide:
0. 24 byte or 32 byte size ( particularly, 3 or 4 times the size of the pointer type, so , a 32 bit version will be 12 bytes or 16bytes respectively).
1.Unicode , ascii and arbitrary Encodings standard support .
2. A SSO buffer with the size of the buffer being only one byte less than the size of the string object :(23 byte or 31 byte).
3. Copy on Write .
4. Shared substrings .
5. String view behavior with no allocation for static strings.
6. Error code behavior for string errors without any exception .
7. FULLY CONSTEXPR CAPABLE.
8.thread safe (by deafult , but not in constexpr mode).
9. almost all functions are noexcept.
10. In the 32 byte version, the hash map lookups will be faster because of the storage of hash value
If you have any questions or concerns or opinions or criticisms , please let me know in the comments.
EDIT:
added space between lines.
Added clarity for why 32 or 24 are stated .
Fix for ordering
Note:
This is for c++20 , but I suppose that a non constexpr version could be made for even c++11
https://redd.it/1ed0ypx
@r_cpp
is this interesting enough?
I really what to make the best string class in terms of memory efficiency and customizability and performance,
I know ,It sounds too good to be true.
Soo , I want to share my general plans for how it is , and then you rate it, and say what is its weaknesses and ect.
( I don't count the time for writing the string library code base).
(Note: I've made a constexpr capable prototype of the 24 byte layout, and it's functional , if you only consider using ascii, but for others , i have no idea for implementing unicode string mutation functions, and almost all of the functions have the noexcept specifier )
First.
It has 2 different object layouts (you chose it by a template flag):
A. 32byte layout:
1.sso size(bytes) = 31 - int(hasnull);
2.Has a hash section for optomizing hash map lookups
B.24 byte :
1.sso size(bytes) = 23 - int(hasnull);
Second. It has a control byte(the last byte of the object) with these :
0.has soo flag
1. Has null flag
2.is thread-safe ( constexpr mode cannot be thread-safe)
3. Encoding standard (5 bit value, zero means Ascii)
// note : we use pragma pack , but make sure all of them are aligned properly .
Third. non sso data menbers:
CharHeap_data_ptr;
Const char beginptr;
Uintptrt hashvar;(only in 32byte mode)
Char rawlengthvar[sizeof(void*)-1];( the last byte is packed and is the control byte).
Forth.modes:
0.SSO:
The data is in the string internal buffer and can be modified if the owner is non const.
Also , we are not allowed to access the sso data menbers , because that union member is inactive.
1. Stringview:
It is when the Heapdataptr is null but the beginptr is not.
Is tells us that the string is CONSTANT.
2.error value:
It is when Heapdataptr and beginptr are both null,
And the value in the length variable indicates the error value.
2.heap string(with reference count systems ) :
In this mode the Heapdataptr is not null , and points to the capacity and reference count variables that are at the beginning of the heap string data buffer.
The reference count is a 64 bit variable that is used as two combined 32 bit variables with names of :
Strong ref count and week ref count.
(The reference count system is like the system used in sheared ptr, but in a constexpr and thread friendly way )(is thread-safe flags says that the variable is atomic or not)
We can modify( by a verified const cast ) the data , if the Strong reference count value is one.
But if it's not one , we can only read the data.
Note: Copy on Write is used , In a thread-safe way.
fifth. The view and share system:
By allowing the begin and heap pointer to be separated, we have the ability to use different parts of a string, even if we are not in string view mode , and the substring function is now copy on write capable.
// note : this part is only customizable by template APIs and it is not visible for the user of the string class, the user SHALL use the string, in a way witch is user friendly
Sixth.The custom Allocator and the fast string usage :
If we wish to modify the string dara , we have to extract the string to a 48 or 56 byte string temporary, witch is fast to use , and is not as packed as the original 24 or 32 byte data
In addition, we provide a pointer to a Allocator for the string to use .
And this way, we don't need a redundant allocator pointer for each member of the string rope vector (the next plan).
But if the Allocator is not trivial, the user string class has to have the burden of carrying it ,unless the user is a mad man who likes to extract strings before usage.
Note: at the end of the temporary's lifetime, we compress the data back to the original string 24 or 32 byte object.
IMPORTANT: the mad man shall not use the original string , while the temporary is still alive .
Seventh. Plans for the future by using a vector of strings as a rpoe:
By having the ability to use shared string subparts and constant views , we can make a very effective rope class that is itself a string vector under the hood ,
Boost 1.86 beta 1 is out
https://www.boost.org/users/history/version_1_86_0.html
https://redd.it/1ecv08e
@r_cpp
Confused what should I do ?
n
I was learning dsa from last 3 months ,till now I have completed array,linked list, recursion,stack ,queue Now I am approaching tree but I unable to Understand it .What should I do further and how to come out of this situation?
https://redd.it/1ecoric
@r_cpp
For Better or for Worse, the Overload | consteval
https://consteval.ca/2024/07/25/overload/
https://redd.it/1ecgwjk
@r_cpp
gpu.cpp: portable GPU compute for C++ with WebGPU
https://www.answer.ai/posts/2024-07-11--gpu-cpp.html
https://redd.it/1ec7syr
@r_cpp
Why use C over C++
Why there are so many people using the C language instead of C++?, I mean C++ has more Cool features and the Compiler also supports many CPUs. So why People still using C?
https://redd.it/1ebzawj
@r_cpp
Review my code - custom vector class
Can you see the any mistakes or bad practices in code below, I am still progressing in my C++ abilities currently and I wonder people's opinions about it, thanks..
#ifndef SANDBOX_HPP
#define SANDBOX_HPP
#include <iostream>
#include <string>
#include <initializer_list>
template <typename T>
class Vector
{
private:
T* m_storage;
size_t m_usage;
size_t m_capacity;
public:
// Default Constructor
Vector();
// Parametic Constructor
Vector(int capacity);
// Initializer-list Constructor
Vector(const std::initializer_list<T>& list);
// Copy Constructor
Vector(const Vector<T>& other);
// Copy Assignment
Vector<T>& operator=(const Vector<T>& rhs);
// Move Constructor
Vector(Vector&& other);
// Move Assignment
Vector& operator=(Vector&& rhs);
// Destructor
~Vector();
// Emptiness check
bool isEmpty() const;
// Fullnes check
bool isFull() const;
// Expand the array
void expand();
// Push element
void push(const T& val);
// Get element
T& operator[](int index);
// Return array size
size_t size() const;
};
// DEFINITIONS /////////
template <typename T>
Vector<T>::Vector() : Vector(2)
{}
template <typename T>
Vector<T>::Vector(int capacity) : m_usage(0), m_capacity(capacity), m_storage(new T[capacity])
{}
template <typename T>
Vector<T>::Vector(const std::initializer_list<T>& list) : Vector(list.size())
{
m_usage = list.size();
int i = 0;
for (auto& x : list)
{
m_storage[i] = x;
i++;
}
}
template <typename T>
Vector<T>::Vector(const Vector<T>& other) : m_usage(other.m_usage), m_capacity(other.m_capacity), m_storage(new T[other.m_capacity])
{
for (int i = 0; i < other.m_usage; i++)
m_storage[i] = other.m_storage[i];
}
template <typename T>
Vector<T>& Vector<T>::operator=(const Vector<T>& rhs)
{
if (this == &rhs)
{
std::cerr << "Vector& operator=(const Vector& rhs): same operands!\n";
exit(EXIT_FAILURE);
}
m_usage = rhs.m_usage;
m_capacity = rhs.m_capacity;
m_storage = new T[m_capacity];
for (int i = 0; i < rhs.m_usage; i++)
m_storage[i] = rhs.m_storage[i];
return *this;
}
template <typename T>
Vector<T>::Vector(Vector<T>&& other) : m_usage(other.m_usage), m_capacity(other.m_capacity), m_storage(other.m_storage)
{
other.m_storage = nullptr;
other.m_capacity = 0;
other.m_usage = 0;
}
template <typename T>
Vector<T>& Vector<T>::operator=(Vector<T>&& rhs)
{
if (this == &rhs)
{
std::cerr << "Vector& operator=(Vector&& rhs): same operands!\n";
exit(EXIT_FAILURE);
}
m_usage = rhs.m_usage;
m_capacity = rhs.m_capacity;
if (m_storage)
{
delete[] m_storage;
}
m_storage = rhs.m_storage;
rhs.m_storage = nullptr;
rhs.m_capacity = 0;
rhs.m_usage = 0;
return *this;
}
template <typename T>
Vector<T>::~Vector()
{
delete[] m_storage;
}
template <typename T>
bool Vector<T>::isEmpty() const
{
return m_usage == 0;
}
template <typename T>
bool Vector<T>::isFull() const
{
return m_usage == m_capacity;
}
template <typename T>
void Vector<T>::expand()
{
m_capacity *= 2;
T* newStorage = new T[m_capacity];
for (int i = 0; i <
SetLang cpp
I have a project that I’m working on about SetLang. I need some help with it is anyone willing to help ?
https://redd.it/1ebujp8
@r_cpp
Is there a working implementation of std::flatmap and std::flatset?
https://redd.it/1ebrria
@r_cpp
Where do you use C++?
Basically, I am just very curious about your job descriptions as C++ devs xD.
I mean, as a C++ developer, what are you currently working on?
https://redd.it/1ebngmo
@r_cpp
Whenever I try to run anything this error shows, what should I do
if ($?) { g++ array.cpp -o array } ; if ($?) { .\\array }
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
https://redd.it/1edkiab
@r_cpp
Embedded systems
I'm interested in learning embedded systems. Can anyone share their experiences and insights on whether it's a good field to pursue? What are the career prospects and key skills needed for success in this area?
https://redd.it/1edcnog
@r_cpp
Cpp open mp package cannot be installed in my macbook air m2
C++ Package open mp cannot be installed
Guys I tried home brew package downloader on my MAC also but I can't install the openmp package to use ->opm header in my c++ code for parallel processing using c++ . In online and chat gpt and other yt sources show to download Limbomp using home brew I tried that it is not working and I can't find any other method
If anyone have any working solution
Please let me know by comments 🙏🏻
https://redd.it/1edd2z3
@r_cpp
is this interesting enough?
I really what to make the best string class in terms of memory efficiency and customizability and performance,
I know ,It sounds too good to be true.
Soo , I want to share my general plans for how it is , and then you rate it, and say what is its weaknesses and ect.
( I don't count the time for writing the string library code base).
(Note: I've made a constexpr capable prototype of the 24 byte layout, and it's functional , if you only consider using ascii, but for others , i have no idea for implementing unicode string mutation functions, and almost all of the functions have the noexcept specifier )
First.
It has 2 different object layouts (you chose it by a template flag):
A. 32byte layout:
1.sso size(bytes) = 31 - int(has_null);
2.Has a hash section for optomizing hash map lookups
B.24 byte :
1.sso size(bytes) = 23 - int(has_null);
Second. It has a control byte(the last byte of the object) with these :
0.has soo flag
1. Has null flag
2.is thread-safe ( constexpr mode cannot be thread-safe)
3. Encoding standard (5 bit value, zero means Ascii)
// note : we use pragma pack , but make sure all of them are aligned properly .
Third. non sso data menbers:
Char*Heap_data_ptr;
Const char* begin_ptr;
Uintptr_t hash_var;(only in 32byte mode)
Char raw_length_var[sizeof(void*)-1];( the last byte is packed and is the control byte).
Forth.modes:
0.SSO:
The data is in the string internal buffer and can be modified if the owner is non const.
Also , we are not allowed to access the sso data menbers , because that union member is inactive.
1. String_view:
It is when the Heap_data_ptr is null but the begin_ptr is not.
Is tells us that the string is CONSTANT.
2.error value:
It is when Heap_data_ptr and begin_ptr are both null,
And the value in the length variable indicates the error value.
2.heap string(with reference count systems ) :
In this mode the Heap_data_ptr is not null , and points to the capacity and reference count variables that are at the beginning of the heap string data buffer.
The reference count is a 64 bit variable that is used as two combined 32 bit variables with names of :
Strong ref count and week ref count.
(The reference count system is like the system used in sheared ptr, but in a constexpr and thread friendly way )(is thread-safe flags says that the variable is atomic or not)
We can modify( by a verified const cast ) the data , if the Strong reference count value is one.
But if it's not one , we can only read the data.
Note: Copy on Write is used , In a thread-safe way.
fifth. The view and share system:
By allowing the begin and heap pointer to be separated, we have the ability to use different parts of a string, even if we are not in string view mode , and the substring function is now copy on write capable.
// note : this part is only customizable by template APIs and it is not visible for the user of the string class, the user SHALL use the string, in a way witch is user friendly
Sixth.The custom Allocator and the fast string usage :
If we wish to modify the string dara , we have to extract the string to a 48 or 56 byte string temporary, witch is fast to use , and is not as packed as the original 24 or 32 byte data
In addition, we provide a pointer to a Allocator for the string to use .
And this way, we don't need a redundant allocator pointer for each member of the string rope vector (the next plan).
But if the Allocator is not trivial, the user string class has to have the burden of carrying it ,unless the user is a mad man who likes to extract strings before usage.
Note: at the end of the temporary's lifetime, we compress the data back to the original string 24 or 32 byte object.
IMPORTANT: the mad man shall not use the original string , while the temporary is still alive .
Seventh. Plans for the future by using a vector of strings as a rpoe:
By having the ability to use shared string subparts and constant views , we can make a very effective rope class that is itself a string vector under the hood ,
GDB, A Lot More Than You Knew!
https://youtube.com/shorts/FzkWG1Ljbug?feature=share
https://redd.it/1ed1yi8
@r_cpp
Dingo - Dependency Injection Library for C++
Hi all, I would like to present a C++ Dependency Injection library I've been working on for some time and gather a feedback and interesting ideas to follow - https://github.com/romanpauk/dingo
The design of the library is influenced by what seemed useful, interesting or lacking in code I've been involved with. It is non-intrusive, uses runtime resolution, does not impose restrictions on types it works with or instantiates and generally tries to "stay low and support whatever is there". It provides some features that seemed useful like container nesting, named resolution, multi-bindings and support for code bases without RTTI, among others.
I understand that some people see this problem as an antipattern or as a manifestation of some more serious problem, and that can be only agreed with. Yet such libraries exist and are used, so I would also be grateful to hear what are you using and why and what problems do you encounter while doing so.
https://redd.it/1ecpckf
@r_cpp
Bitwise and how I should use it
Hey guys I'm wondering what kind of things to use Bitwise with and thank you all
https://redd.it/1ecmwuz
@r_cpp
Implementation of std::underlyingtype<T> ?
I tried to trace it down on linux, but only get to \_underlying_type. Can anyone help? Thanks a lot!
https://redd.it/1ecgd5s
@r_cpp
New to cpp
Hello 👋🏼, I am just getting started with c++! What should I know and take note of? I have intermediate python knowledge and some c knowledge… currently on the c++ crash course by bro code! My goal is to implement a tensorflow project in c++!
Thanks
https://redd.it/1ecfvuo
@r_cpp
Compile-time max length from array of std::string_view literals
Hello! I've been playing around with templates/`constexpr` and hit this problem. I have a `constexpr` array of `string_view` literals from which I would like to obtain the length of the longest string *at compile time* for use in a formatting specifier. Here is the array:
constexpr std::array loggingLabels = {
"NONE"sv,
"ERROR"sv,
"WARNING"sv,
"INFO"sv,
"DEBUG"sv
};
Of course, I know that the longest string is `"WARNING"`, with length `7`, and that this is a slightly contrived problem, but would like to do this programmatically if possible.
I tried using applying a lambda `auto getLength = [](decltype(loggingLabels[0]) str) { return str.size(); };` using various `std::ranges` functions (followed by `std::ranges::max`) but couldn't find a function that would output a transformed range of a different type to the input range.
I also tried using templates, and came up with this:
template <class... Strings>
constexpr auto maxLength(const Strings... strs) {
return std::max({strs.size()...});
}
...though then realised that I couldn't transform the array into a parameter pack to instantiate the template.
I am very new to TMP and ranges, so apologies if I am missing anything simple. I would greatly appreciate any pointers on how to proceed!
Edit: missing a `;`
https://redd.it/1ec3s1i
@r_cpp
m_usage; i++)
{
newStorage[i] = m_storage[i];
}
delete[] m_storage;
m_storage = newStorage;
}
template <typename T>
void Vector<T>::push(const T& val)
{
if (this->isFull())
this->expand();
m_storage[m_usage] = val;
m_usage++;
}
template <typename T>
T& Vector<T>::operator[](int index)
{
return m_storage[index];
}
template <typename T>
size_t Vector<T>::size() const
{
return m_usage;
}
#endif // SANDBOX_HPP
https://redd.it/1ebxj17
@r_cpp
Built a simple http server in C++
I have built a simple http server in C++ that serves static files only. I learnt alot building this project.I am thinking of making it a small lib but i am not sure.
What i need is a feedback before I continue.
Thanks
Github:
https://github.com/nyx6965/http
https://redd.it/1ebwh3l
@r_cpp
Using Docker Container as a Development Environment
Finished another YouTube video today on the "Improving Your C++ Development Pipeline" series. This one is on using a Docker Container as a Development Environment.
https://youtu.be/gMTXTak\_qF4
Reasoning, pros and cons are in the Introduction video in the same playlist. I wanted to focus on a straight walk through.
https://redd.it/1ebtann
@r_cpp
Finance And C++
From my college days I used to practice data structures and algorithms in c++. I like have practiced a lot in c++ related to data structures and algorithms, but now i want to make something useful out of it. I want to use it in development. So I researched a little bit and came to know that you can learn about Quant Finance or High frequency trading using C++ or algorithm developer. Can anyone help me i want to explore these fields, I want to know about resources in Quant Finance, High frequency trading and Algorithms developer in c++.
TLDR;
I want to explore Quant Finance, High frequency trading and want to explore field of algorithm developer using c++.
https://redd.it/1ebqzem
@r_cpp
Implement RabbitMQ (AMQP) or Kafka Protocols in C++
We are considering offering our internally developed message queue service to external users (possibly as an open-source project). We are currently deciding whether to implement the RabbitMQ or Kafka protocol, aiming to integrate with the existing ecosystem more quickly. From our experience, Kafka seems easier to implement. However, Kafka has multiple versions and a variety of clients, which might introduce some challenges.
Our core requirements are:
- Protocol Extensibility: We may need to implement some custom features for internal use.
- Ease of Maintenance. Ease of Development: We do not necessarily need to implement the entire protocol, just the core functionalities. We noticed that AWS’s Kafka services do not provide all features either.
- Ease of Integration with Existing Ecosystem: We are concerned about potential issues with Kafka, mainly due to frequent protocol changes. RabbitMQ, on the other hand, primarily uses AMQP 0-9-1.
Could you provide advice based on these requirements?
https://redd.it/1eblftx
@r_cpp