C++ implementation explained

Compare it with the naive implementation: template< class InputIt, class Size, class OutputIt> OutputIt copy_n(InputIt first, Size count, OutputIt result) { for (Size i = 0; i < count; ++i) { *result++ = *first++; } return result; } This version does one more increment of first! count==0, both do 0 increments of first. count==1, their … Read more

Using local classes with STL algorithms

It’s explicitly forbidden by the C++98/03 standard. C++11 remove that restriction. To be more complete : The restrictions on types that are used as template parameters are listed in article 14.3.1 of the C++03 (and C++98) standard: A local type, a type with no linkage, an unnamed type or a type compounded from any of … Read more

Why are std::shuffle methods being deprecated in C++14?

std::random_shuffle may make use, under the hood, of random C family of functions. These functions use global state for seeds and other state. So it is being deprecated because shuffle will do the same, but better. Namely, it uses the new <random> header from C++11 that doesn’t use global state, but its own objects making … Read more

Why is there no transform_if in the C++ standard library?

The standard library favours elementary algorithms. Containers and algorithms should be independent of each other if possible. Likewise, algorithms that can be composed of existing algorithms are only rarely included, as shorthand. If you require a transform if, you can trivially write it. If you want it /today/, composing of ready-mades and not incur overhead, … Read more

How to find the intersection of two STL sets?

You haven’t provided an output iterator for set_intersection template <class InputIterator1, class InputIterator2, class OutputIterator> OutputIterator set_intersection ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result ); Fix this by doing something like …; set<int> intersect; set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), std::inserter(intersect, intersect.begin())); You need a std::insert iterator since the set is as of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)