Source codes of Discovering Modern C++
petergottschling / discovering_modern_cpp Goto Github PK
View Code? Open in Web Editor NEWSource codes of Discovering Modern C++
Source codes of Discovering Modern C++
When looking at the Function Dispatching example, shown in 4-1, something looks amiss. I tried typing it in as shown, but was quite suspicious of the advance
template. Couldn't get it to work, so i pulled the repo and looked at the advance_test.cpp file in c++11 directory. I compiled it as is (more or less) and it worked ( after changing the iterator up a bit. A forward_list isn't going to support reverse iteration, right?.):
auto it= l.begin();
advance(it, 2);
cout << *it << '\n';
However, after setting #if 0
to #if 1
it ceased to compile. I decided to fix what was bothering me. That last advance template is defined in relation to advance. However, I assume that you meant advance_aux; otherwise, what is the point of defining all the specializations?
So, I change the template function ( or is it function template ? ):
template <typename Iterator, typename Distance>
inline void advance2(Iterator& i, Distance n)
{
advance_aux(i, n, typename iterator_category<Iterator>::type());
}
But that didn't work. But something was bugging me about the third line.. A little swearing and googling and i came up with this, which works:
template <typename Iterator, typename Distance>
inline void advance2(Iterator& i, Distance n)
{
advance_aux(i, n, typename iterator_traits<Iterator>::iterator_category());
}
It is unfortunate that this doesn't work out of the gate. This example code as printed in the book seems flawed, especially considering there is no real description of what is going on at this point. I bought the book despite concerns raised about code quality in some of the reviews and have found it generally great; hopefully this is an outlier, or perhaps i have misunderstood the issue.
Hi Peter,
unfortunately I couldn't find a mail address of you anywhere, therefore I'm opening up an issue here:
I've found several typos and small errors in your book and wondered how to report them appropriately.
Provided there will be a second edition some time in the future and or there will be an errata, I will happily report any issues I will find while reading this book.
c++11/template_type_deduction.cpp includes ../myinfo.hpp which is missing. P109 in the book.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.