Click here to Skip to main content
15,885,914 members
Everything / Programming Languages / C++20

C++20

C++20

Great Reads

by Bruno van Dooren
How concepts can be used in template programming for partial specialization
by Mladen Janković
Improved algorithm for reconstructing game world map from captured game play
by Bruno van Dooren
This article describes a way to hash data using the latest Win32 API and C++
by Claudio Farassino
A small and simple C++ GroupBy with the same syntax and use of DotNet GroupBy

Latest Articles

by Jovibor
Library for parsing internal structures of PE32/PE32+ binary files.
by Coral Kashri
std::string_view can optimize both performance and code readability in code sections which handle strings, but, it can also lead to UB and memory issues if used incorrectly.
by Coral Kashri
How compiler helps code run faster and generates warnings in single cross-compiler way

All Articles

Sort by Score

C++20 

8 Sep 2022 by Bruno van Dooren
How concepts can be used in template programming for partial specialization
9 Sep 2021 by Mladen Janković
Improved algorithm for reconstructing game world map from captured game play
26 Aug 2022 by Bruno van Dooren
This article describes a way to hash data using the latest Win32 API and C++
17 Mar 2023 by Claudio Farassino
A small and simple C++ GroupBy with the same syntax and use of DotNet GroupBy
19 Sep 2020 by sdancer75
A graphical time line editor to help you create and prototype animations. It is useful for adjusting variables and checking out how the effects change over time with keyframing and easing/twining functions.
15 Dec 2021 by Greg Utas
You can't specialize the function template without also specializing the class template to which it belongs. See here[^].
31 Dec 2021 by Richard MacCutchan
You could probably simplify that by the use of the singleton pattern - Google Search[^].
5 Jan 2022 by Stefan_Lang
You seem to try and imprint another languages' properties onto C++, and that is never a good idea! My experience with java is limited, and I'm not sure what you actually have in mind, but the code you posted is clearly not the recommended way of...
25 Jan 2022 by Stefan_Lang
Quote: How do we do it right 1. Post your actual question at the top, maybe even in the topic heading 2. Provide your goal and relevant detail information after that, in the body of your posting. Make sure to keep it reasonably short by...
2 Feb 2023 by Bruno van Dooren
Ways to enforce an interface contract on static methods, similar to what you would expect from static virtual methods if they'd exist in C++
22 Apr 2023 by Coral Kashri
About C++20 Ranges library
17 Sep 2023 by Michael Haephrati
The best solution I found is but it seems to be a flaw in std::format. #include #include #include #include #include #include #include #include std::string...
15 Jul 2021 by OriginalGriff
Spelling is all ... change: #define HANDLE_NULL_BUFFER(buffer_identifer) DEBUG_ASSERT(buffer_identifier != nullptr) To #define HANDLE_NULL_BUFFER(buffer_identifier) DEBUG_ASSERT(buffer_identifier != nullptr) ...
27 Jan 2022 by Stefan_Lang
Quote: The problem was I cannot properly separate the declaration & definition of a templated symbols such as classes, structs, functions, and many more Short answer: you cannot! From the link I posted above (emphasis mine): Quote: However, when...
5 Dec 2022 by OriginalGriff
Quote: The below code is what I have tried but it's entirely wrong! Yes. It is. And you don't know why. Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your...
24 Dec 2022 by honey the codewitch
Your code initially looked fine to me and then I saw it. You can't specialize by number of template arguments in C++ because you must have parameters after struct xyz, such as struct xyz as specializations require some of the template...
25 Nov 2020 by Mladen Janković
Data structure that allows items to be scheduled for processing based on the tags that define item hierarchy
28 Apr 2021 by Rick York
This is not a code conversion service but I will give you a hint. The Pascal for loop of this form : for x1 :=0 to 12 do looks like this in c++ : for( x1 = 0; x1
16 Dec 2021 by BernardIE5317
In the code below why is the templated foobar called and not the non-templated version I expect the non-templated version to be called as it is a precise argument match w/ the exception of the const void foobar(const int&) { } // not called...
5 Jan 2022 by Phoenix Liveon
What I did for now was to call/invoked it inside of the first line of one of any constructor, Note: upon by doing it we need to have a delegated constructor if we do had multiple overloaded constructors, so that we could link it together, then...
4 Aug 2022 by Jovibor
PE (x86) and PE+ (x64) files viewer, based on libpe.
17 Aug 2022 by 2022 Dude
in C++ 20, there is a new method for formatting strings, called std::format. However, its hot clear how (and would it be possible) to format the output, especially float values where you would want to control how many digits after the decimal...
15 Aug 2022 by Greg Utas
I've only skimmed this article, but you might find it helpful: An Extraterrestrial Guide to C++20 Text Formatting - C++ Stories[^] If there's already a standard way to do it, that's what I'd use. So far, I've found little use for all the things...
15 Aug 2022 by Richard MacCutchan
See std::formatter - cppreference.com[^] which explains all the fields is a format selector.
16 Oct 2022 by merano99
The command system() creates a new process to handle the specified command. char cmd[10]; strcpy(cmd, "dir"); system(cmd); In most cases, this is neither performant nor useful. But of course you can start a process with C this way. You could...
19 Oct 2022 by Alexandrnn
#include #include int main() { system("dir"); puts((char*)stdin); } #include #include #include int main() { char cmd[10]; strcpy_s(cmd, 10, "dir"); system(cmd); puts((char*)stdin); }
20 Oct 2022 by Rick York
Have you investigated the RegDeleteKeyExA function (winreg.h) - Win32 apps | Microsoft Learn[^] ? Here is another sample : Deleting Registry Key with Subkeys Win32 C program example[^]
5 Dec 2022 by merano99
Saving the calories in a vector would be a good idea. std::vector numbers; Then it would be practical to write the calories as described in a file calories.txt and read this file line by line. At each blank line write the sum into the...
24 Dec 2022 by CPallini
Try template struct xyz { static size_t const data = 1; }; template struct xyz { static size_t const data = 0; }; template struct xyz { static size_t const data = 0; }; auto x1 =...
9 Jun 2022 by BernardIE5317
Greetings Kind Regards I am completely befuddled re/ C++ format. The code below generates the compiler errors shown. Kindly Advise Thank You #include #include void foo(std::string_view _format) { std::cout
18 Jan 2024 by Richard MacCutchan
Maybe this: Constraints and concepts (since C++20) - cppreference.com[^].
26 Sep 2022 by Death Smoke
I'm trying to make a connection between two computers both of them are using tp-link adapter , but i'm not receving anything from client . #include #include using namespace std; int main() { ...
3 May 2021 by OriginalGriff
Your code compiles, runs and produces a correct answer: so what more is necessary? If what you have isn't enough, you need to go back to your exact assignment, read it again very carefully, and work out what exactly it expects you to hand in. ...
3 Jul 2021 by OriginalGriff
Don't post this under Quick Answers - if you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to...
4 Jul 2021 by BernardIE5317
Why is cbase::foobar() not found when called on type cderived while all members of cbase are declared public? This suggests name only is utilized for lookup and signature ignored but that is difficult to believe as one of the benefits of C++ is...
3 Jul 2021 by Richard MacCutchan
See ToDoList 8.0 - An Effective and Flexible Way to Keep on Top of Your Tasks[^]. There is a forum at the end of the article where you can post a message to the author.
4 Jul 2021 by Richard MacCutchan
Variable d is an instantiation of a cderived class. So any call to foobar requires an integer to be passed to it, as per the signature of the function in that class. In order to call the base version you need to cast d to a cbase object thus: ...
5 Jul 2021 by BernardIE5317
Is it possible to write a concept which requires a class type have a particular templated method as below? struct struct_a { template void foobar(T&) {} } template requires templated_foobar // how to write this...
5 Jul 2021 by Richard MacCutchan
See Templates - cppreference.com[^]
5 Jul 2021 by Greg Utas
The page mentioned above links to this[^], which covers the details. Sorry I can't help beyond that, because I don't use constraints.
15 Jul 2021 by BernardIE5317
The C++ code below will not compile w/ error C2065: 'buffer_identifier': undeclared identifier I do not understand why the argument passed to DEBUG_ASSERT from HANDLE_NULL_BUFFER is not replaced by the argument passed to HANDLE_NULL_BUFFER ...
27 Aug 2021 by Khiêm Nguyễn 2021
I created a user-defined literal like this in is OWN .cpp file (declared as a friend function in .h file): fraction operator"" _frac(const long double val) { return fraction(static_cast(val)); } But in main it...
27 Aug 2021 by Rick York
Do you have a prototype for the function defined? Something like : extern fraction operator _frac(const long double val);
21 Nov 2021 by CrystalNeves
Hello. I am trying to implement verlet's algorithm to simulate the interaction of two stars with the same mass as the sun. They are initially 2 parsec away and symetric velocities perpendicular to the axis that passes through their centre. ...
10 Dec 2021 by BernardIE5317
The code below does not link as indicated Kindly advise Thank You struct cfoobar { struct cgoobar { void goobar() const {} }; static cgoobar m_goobar; // error LNK2001: unresolved external symbol "public: static struct cfoobar::cgoobar...
10 Dec 2021 by k5054
As for basic type, you have to initialize the static variable before you can use it struct cfoobar { struct cgoobar { void goobar() const {} } static cgoobar m_goobar; }; cfoobar::cgoobar::m_goobar; //initializes...
10 Dec 2021 by BernardIE5317
#define FUNCSIG cout
15 Dec 2021 by BernardIE5317
I wish to define a specialization of a templated class's templated method outside of the class declaration as shown below However the indicated error message is generated No error occurs if the class is not templated Thank You Kindly ...
22 May 2022 by Phoenix Liveon
�����Is there a way to have this initialization block similar to Java that we could implement and run properly in C++. There were two types of init-block in Java: 1. init-block/raw-init-block, this will invoke at every new instance created. 2....
9 Jun 2022 by Member 14138220
The problem seems to be consteval _Basic_format_string constructor that cannot convert runtime strings like that. std::_Basic_format_string s = _format; I went with using the underlying vformat() method that doesn't enforce this...
31 Aug 2022 by BernardIE5317
Greetings Kind Regards I am attempting to call a C++ routine which accepts a std::optional argument. However when called w / an argument whose type is the contained type it fails to compile stating the template types could not be deduced....
31 Aug 2022 by Greg Utas
The following compiles for me in C++20 (MSVC). I had to add a few missing semicolons and comment out most of the calls to the SHOW macro, which generated errors for too many arguments. I also added spaces around template arguments to prevent left...
31 Aug 2022 by BernardIE5317
Thank You for your kind assistance. Modified code so std::optional is no longer utilized.
6 Sep 2022 by Jörn Kastner
I'm trying to use std::span to use both legacy C arrays and std::strings. Problem is that I can't "clear" spans correctly. Am I missing something? What I have tried: Consider the following code: void ClearSpan(std::span...
19 Oct 2022 by Death Smoke
I Want to convert the output of this code to string type , but i cant make it. #pragma warning(disable : 4996) #include int main() { char cmd[10]; strcpy(cmd, "dir"); system(cmd); } What I have tried: I tried to...
25 Oct 2022 by Michael Haephrati
In the code below you can see how to delete a subkey or the entiry key HKEY hKey = NULL; long lReturn = RegOpenKeyEx( HKEY_USERS. _T("folder \folder\ folder\{Key name}"), 0L, ...
29 Oct 2022 by Utkarsh Singh Rajawat
Like let's say - A a1,a2,a3,a4; a1=a2*a3+a1++/2; Assuming there is a class A and *,+,post increment operator(++) and / are overloaded in class A. a1,a2,a3,a4 are objects of A class. So what's the order of evaluation of operators in above...
29 Oct 2022 by OriginalGriff
That's tricky ... Why Does x = ++x + x++ Give Me the Wrong Answer?[^]
29 Oct 2022 by Richard MacCutchan
See also C++ Operator Precedence - cppreference.com[^].
29 Oct 2022 by Greg Utas
Whether they've been overloaded or not, the compiler generates code to execute operators in the same order. If you read the page that Richard linked, I think you'll discover that you're mistaken about the order in which the evaluation occurs for...
5 Nov 2022 by BernardIE5317
Greetings Kind Regards The routines below do not compile w/ error messages shown. I am mostly interested in the first routine assert_Search_results The error refers to a template parameter being shadowed. I do not know what that means. I seek...
4 Nov 2022 by Richard MacCutchan
This is the same question as How to resolve compile error re/ shadowing of template parameter whatever that may be[^]. Please do not repost.
13 Nov 2022 by BernardIE5317
Greetings Kind Regards I am attempting to utilize C++ std::format and pass the format string by name. However this results in compile error as shown below. I have a very long format string and do not wish to stick it in the call site. I do not...
13 Nov 2022 by Richard MacCutchan
The format string must be a constant expression, see std::format - cppreference.com[^]. [edit] I have been looking at the documentation (per the above link), and trying some tests. Even using the string: const char* fmt = "{}"; produces the...
24 Dec 2022 by hans.sch
I'm trying to understand template specialization in modern C++. The code makes no sense, it is only a proof of concept. (Or rather, a disproof until now.) template struct xyz { static size_t const data = 0; }; template
17 Mar 2023 by Phoenix Liveon
How do we properly create an overloaded operator specifically this "
17 Mar 2023 by klarrra
Find some good help here. https://kbrown.hashnode.dev/c-in-computer-science
27 Mar 2023 by RexyCode
I'm trying to code a timeout function that kicks out the user if he doesn't select any options in a given amount of time. However I'm finding myself stuck in a infinite loop and even my wait timer can't destroy the loop. My code: namespace jsw...
27 Mar 2023 by Mircea Neacsu
The wait function is OK. It's the main loop logic that is not right. The do...while loop has nothing to break it as the wait function is outside the loop. This should work: int main () { using namespace jsw::threading; int option{}; ...
7 Apr 2023 by RexyCode
I'm trying to code a time out "function" that can work in a nested switch and case statement. However my problem is the following, the first switch/case works like expected, on the other hand, the second switch doesn't work in any way. My...
22 Apr 2023 by Coral Kashri
More about explicit(bool) C++20
22 Apr 2023 by Coral Kashri
In this article you will see how to save bytes and alignment when containing some types inside a structure.
22 Apr 2023 by Coral Kashri
How compiler helps code run faster and generates warnings in single cross-compiler way
23 Apr 2023 by Coral Kashri
Iterators Customization
24 Apr 2023 by Coral Kashri
std::string_view can optimize both performance and code readability in code sections which handle strings, but, it can also lead to UB and memory issues if used incorrectly.
30 Jun 2023 by AAisha Sultan Salim Al Kindi
who can i write a algorithm to the question the question said: To write a C++ program to read five integer elements into an array and find their sum please help me to write the algorithm What I have tried: I WRITE THE CODE OF THE QUESTION ...
18 Jan 2024 by Member 14620282
"auto&&" preceded by concept "con" is not a "universal reference as shown below. Remove the constraint by changing "con auto&&" to "auto&&" and it is a "universal reference" (no compilation error). Could someone please explain why? ...
19 Jan 2024 by Maxim Kartavenkov
In your code: template concept con = std::is_class_v && std::derived_from; I guess should be Base instead of base
21 Jan 2024 by Brennon Nevels
I'm in the midst of building a text-based game with hope I can implement an inventory system among other things to make the world interactive. I have already created an item class: enum ItemRange { ShortRange, MidRange, LongRange,...
29 Feb 2024 by Richard MacCutchan
Sorry, this site is not here to do your work for you.
17 Mar 2024 by Jovibor
Library for parsing internal structures of PE32/PE32+ binary files.
14 Dec 2022 by Jovibor
Fully featured Hex Control written in C++/MFC
18 Jan 2021 by Shao Voon Wong
Heterogeneous lookup with char* and string_view without temporary string instantiation in ordered and unordered containers
25 Jan 2022 by Stefan_Lang
I have read, but didn't understand a word of, your question. In the topic header you mention templates, so the only advice I can offer is check out this guide: https://itnext.io/c-20-modules-complete-guide-ae741ddbae3d[^] The section Quote:...
28 Aug 2021 by RegularJoe5150
A reformulation of compressed pair into a type list
19 Oct 2022 by CPallini
Are you possibly searching for popen? See, for instance: The Marvelous popen() Function | C For Dummies Blog[^]
17 Sep 2023 by Richard MacCutchan
Had you read the error message you would see that line 19 has an illegla character. std::ctime(¤tTime), Also, there is no variable named tTime; you most likely meant currentTime. And the macros _FILE_ and _LINE_ are incorrect, they take double...
27 Oct 2022 by Death Smoke
Hi all, I Searched how to delete a whole key from the Registry using c++ anyone here can help me because i didnt find any clear example about this subject. the key path is like here : Computer\HKEY_USERS\folder \folder\ folder\{Key name}. So...
7 Feb 2023 by Ben McNamara
I++ contains AVL databases
16 Mar 2024 by Line Item
I would try running this from a command line, with some adjustments for that to make it a simple command. Get that to work then add to that a little at a time. Maybe then try moving that to PowerShell. Get that to work then add more until you...
28 Apr 2021 by rosmary404
I have the answer to this equation in Pascal. Can anyone help me convert this to c or c ++? equation: y1+y2+y3+y4=12 yi ≥ 0 , 0 ≤ i ≤ 4 pascal code (but i cant run it) : program selections3 (input,output); var x1,x2,x3: integer; begin for x1...
3 Jul 2021 by Member 15274803
Thanks for a great product. I bought a new PC (windows 10 64 bit) and it won't run, saying it needs MS Visual C++ 2010. The link to download MS Visual C++ 2010 is broken. I am also thinking a later version of MS Visual C++ should work. Can...
3 Jul 2021 by BernardIE5317
My thanks to dead.rubber.chicken for directing me to the language rule which I must accept so will utilize using directive to solve problem but still do not understand why the language refuses to support what seems a logical extension to the...
5 Dec 2022 by Harsh 5
The question is straightforward but the only thing I cannot conquer is getting the elf's calorie data as input from the user. I have to read for a new line and whenever I get a new line I have to update my sum to the maximum calorie/sum an elf...
21 Nov 2021 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email...
27 Jan 2022 by Phoenix Liveon
The problem was I cannot properly separate the declaration & definition of a templated symbols such as classes, structs, functions, and many more. Before we could continue I have this quick statement on how I organized my work/project. We can...
30 Jun 2023 by Member 16040932
#include using namespace std; int main(){ int arr[5];int sum = 0; for(int i = 0 ;i>arr[i]; sum+=arr[i]; //short and efficient code; } cout