errata for "Introduction to Boost. Beyond the Standard Library" by Björn Karlsson

(1st printing)

As soon as Björn is online with his site I'll add the according link :)

where erratum correct
page 55,
missing return type:
template <class Target, class Source>
polymorphic_cast (Source*)
template <class Target, class Source>
Target polymorphic_cast (Source*)
page 100 boost::enable_if<has_type<T>, void>::type equivalent to:
enable_if<has_type<T> >::type
page 101 boost::enable_if<false>::type
problem 1: wrong syntax
problem 2: return type is not void
problem 1:
ad 1a:enable_if<bool_<false> >::type
ad 1b:enable_if_c<false>::type
page 108,
T operator+=(const T&);
T operator-=(const T&, const T&);
T operator|=(const T&, const T&);
T operator&=(const T&, const T&);
ad sub:
T operator-=(const T&);
T operator-=(const T&);
ad or:
T operator|=(const T&);
ad and:
T operator&=(const T&);
page 117 CRTP == Barton-Nackman-trick (incorrect) see the Barton-Nackman-trick confusion
page 168 std::map std::vector
page 229 boost::tuples::element<0,Tuple> boost::tuples::element<0,Tuple>::type
page 232 typedef ... mytuple never used

page 286: we are slightly modifying the example from page 286 to show the problem. Instead of vec we use vec1 and vec2.

vector<int> vec1;   // contains some elements
vector<int> vec2;   // empty
a. using the STL:
transform (vec1.begin(), vec1.end(), vec2.begin(), bind1st(plus<int>, 4));
b. in the book:
transform (vec1.begin(), vec1.end(), vec2.begin(), _1 += 4);
version b. modifies vec1 and vec2 where a. alters only vec2.

c. the corresponding lambda-version to a. is
transform (vec1.begin(), vec1.end(), vec2.begin(), _1 + 4);   // + instead of +=
d. if the operation is in situ one could alternatively use the more compact form applying for_each instead of transfrom (version c.) as presented in the book
for_each (vec.begin(), vec.end(), _1 += 4);

page 291 (note): Even though you can achieve the same thing in two different ways using "boost/lambda/bind.hpp" and "boost/bind.hpp" you must carefully disambiguate the symbols and use a slightly different notation. In addition, the function object ap must meet different specs for the return-type. Specifically, boost::lambda::bind expects a nested template class sig whereas boost::bind kindly accepts the STL typedef result_type.

a. using "boost/lambda/bind.hpp"

transform (vec.begin (), vec.end (), vec.begin ()), 
   boost::lambda::bind(boost::lambda::var(ap), boost::lambda::_1));
b. using "boost/bind.hpp"
transform (vec.begin (), vec.end (), vec.begin (),
   boost::bind(ap, _1));

page 292 incorrectly rephrased from lambda-lib-docu 1. If the function object defines several function call operators, there is no way to specify different result types for them.
2. If the function call operator is a template, the result type may depend on the template parameters. Hence, the typedef ought to be a template too, which the C++ language does not support.
page 319, 320 in class notifier: useless member value_ purge value_

page 319: in class notifier one could rewrite the code for change_value as follows

#include <boost/bind.hpp>
#include <boost/bind/apply.hpp>

void notifier::change_value (int i)
   for_each (vec_.begin (), vec_.end (), bind (apply<void> (), _1, i));
instead of
void notifier::change_value (int i)
   for (std::size_t i=1;i<vec_.size();++i) {