modern-cpp | Slides for a course on Modern C | Learning library
kandi X-RAY | modern-cpp Summary
kandi X-RAY | modern-cpp Summary
Slides for a course on Modern C++.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of modern-cpp
modern-cpp Key Features
modern-cpp Examples and Code Snippets
Community Discussions
Trending Discussions on modern-cpp
QUESTION
The compilator says:
"No callable 'begin' function found for type Array< int> * "
"No callable 'end' function found for type Array< int> * "
"it undeclared identifier"
In the print function, I try to iterate through my array of pointers using for(auto it: this). I followed this tutorial to create a custom iterator and I don't know what I did wrong. I'm not very sure if my iterator structure is defined correctly because in his example his using a simple array of integers and I have an array of pointers to a T type. My question is, what exactly should I edit to make the iterator working fine. I think I should edit some types from struct Iterator, but I'm not very sure what to edit. I use the auto keyword on the bottom, on the print function. Thanks in advice!
Full source code for my class is: Array.h
...ANSWER
Answered 2021-May-22 at 14:04Solved by changing some types from the structure. Because It is an array of pointers, it needs to have:
value_type should be a T* because every element from the array is a pointer
pointer should be a T** because it points to an array of pointers
and reference should be a T*& because is a reference through a pointer element from the array.
Also, with some help from MatG, the for(auto it: this) should be changed to for(auto it: *this), because we need to use the dereferenced value of this class. Please correct me if I'm wrong
QUESTION
I was reading Chapter 8 of the "Modern C++ Programming Cookbook, 2nd edition" on concurrency and stumbled upon something that puzzles me.
The author implements different versions of parallel map and reduce functions using std::thread
and std::async
. The implementations are really close; for example, the heart of the parallel_map
functions are
ANSWER
Answered 2021-May-08 at 10:25My original interpretation was incorrect. Refer to @OznOg's answer below.
Modified Answer:
I created a simple benchmark that uses std::async
and std::thread
to do some tiny tasks:
QUESTION
Here is my code:
...ANSWER
Answered 2021-Apr-11 at 09:49How can I call this function with both class A and B?
Both std::shared_ptr
and std::shared_ptr
are convertible to std::shared_ptr
, which is what your function expects, so providing a shared pointer will work.
QUESTION
When seaching for std::future::then on google, the top result is a stackoverflow question about the status of the function in c++17. Now that c++20 has been finalized and Clang and GCC is well into implementing c++20, I am left wondering what is the status of the function and the Concurrency TS generally?
It isn't mentioned on the implementation status page of libc++, libstdc++ or the implementation status page maintained by cppreference), and the TS page on cppreference doesn't say anything about current status.
I have also tried running some very simple examples on Godbolt, but neither are able to find , and not because it has been moved to the header (neither can find future::then.
Additionally, the internet has not been especially helpful. At least I can only find blog posts from 1-2 years ago talking about "hoping" to get the Concurrency TS in c++20, but cannot find any mentions in numerous overviews of new c++ 20 features (a few examples.
Has the Concurrency TS been dropped?
...ANSWER
Answered 2020-Aug-11 at 14:32Has the Concurrency TS been dropped?
Yes.
P1445 discusses this, SG1 voted to withdraw the TS. Note that atomic smart pointers, latches, and barriers are in C++20.
As far as improving future
goes, the direction there is called executors and the design currently being iterated on is P0443, which allows for lazy composition of work in a way that would be much more efficient than future::then
. Two of the authors gave a talk on this at CppCon that goes into the issues pretty well.
QUESTION
From https://docs.microsoft.com/en-us/cpp/cpp/value-types-modern-cpp?view=vs-2019, we have:
...ANSWER
Answered 2020-Aug-04 at 03:59I think the comment means that the strings are moved instead of deep copied. It's still a linear time operation with respect to the number of strings in the vector, but it won't copy all the characters in the strings (maybe except for SSO). That's what "just 1M ptr/len assignments" means. I guess you could consider that "efficient" when compared to copying every character.
QUESTION
I didn't know how to name the title, hopefully its correct...
I stumbled upon below lambda definition, and don't understand the syntax, wht is the meaning of var = [=]
and return [=]
?
also second question in ConstexprLambda()
function below, why can't we must call add(1, 2)
instead of add(1, 2)()
why need for additional ()
while in the call to identity(123)
the code makes not use of additional ()
?
question(s) is put into comments of the code.
...ANSWER
Answered 2019-Oct-06 at 12:53Let's start from the type
QUESTION
Very simple question, I'm unable to google out the answer.
For example:
...ANSWER
Answered 2019-Jun-11 at 11:01All of them are of type int&
.
Adding parentheses like (a)
makes them expressions (instead of entity), which are all lvalues (as named variables); then decltype
yields to T&
, i.e. int&
here.
...
4) If the argument is any other expression of type
T
, and...
b) if the value category of expression is lvalue, then decltype yields
T&
;...
You can check the actual types with this LIVE DEMO (from the compiling error messages).
QUESTION
Reference: Effective Modern C++ Item 4.
...ANSWER
Answered 2017-Jan-07 at 02:34Question> Why the real type of param is Widget const * const & instead?
I'm not really an expert but... because T
is a pointer and if you write const T &
(that is T const &
because the rule is that const
apply on the element on the left or on the element on the right in there isn't an element on the left) you are imposing that the full T
type, so the pointer, is constant.
And to impose that the pointer is constant, you have to impose cont
on the left of the *
.
In brief: const T &
is equivalent to T const &
; with T
that is const Widget *
, T const &
become const Widget * const &
or, if you prefer, Widget const * const &
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install modern-cpp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page