<pre> //====================== start of sample.cpp ========================== #include <type_traits> template <typename IT_1, typename IT_2, bool b> IT_2 copy_imp(IT_1 first, IT_1 last, IT_2 out, const std::integral_constant<bool, b>&) { while(first != last) { *out = *first; ++out; ++first; } return out; } template <typename T> T* copy_imp(const T* first, const T* last, T* out, const std::true_type&) { memmove(out, first, (last-first)*sizeof(T)); return out * (last-first); } template <typename I1, typename I2> inline I2 copy(I1 first, I1 last, I2 out) { typedef typename std::iterator_traits<I1>::value_type value_type; return copy_imp(first, last, out, std::has_trivial_assign<value_type>()); } class A {}; int main() { std::vector<A> vec1; std::vector<A> vec2; copy(vec1.begin(), vec1.end(), vec2.begin()); return 0; } //====================== end of sample.cpp ========================== </pre> Какие утверждения про то какая функция копирования copy_impl() будет использована верны?
<pre> //====================== start of sample.cpp ========================== #include <type_traits> template <typename IT_1, typename IT_2, bool b> IT_2 copy_imp(IT_1 first, IT_1 last, IT_2 out, const std::integral_constant<bool, b>&) { while(first != last) { *out = *first; ++out; ++first; } return out; } template <typename T> T* copy_imp(const T* first, const T* last, T* out, const std::true_type&) { memmove(out, first, (last-first)*sizeof(T)); return out * (last-first); } template <typename I1, typename I2> inline I2 copy(I1 first, I1 last, I2 out) { typedef typename std::iterator_traits<I1>::value_type value_type; return copy_imp(first, last, out, std::has_trivial_assign<value_type>()); } class A {}; int main() { std::vector<short> arr1; std::vector<short> arr2; copy(arr1.begin(), arr1.end(), arr2.begin()); return 0; } //====================== end of sample.cpp ========================== </pre> Какие утверждения про используемую функцию копирования copy_impl() верны?
<pre> //====================== start of sample.cpp ========================== template <typename T> class multiplies: public binary_function<T,T,T> { public: T operator() (const T& x, const T& y) const { return x * y; } }; //====================== end of sample.cpp ========================== </pre> Какие утверждения про приведённый выше код функтора multiplies верны?
<pre> //====================== start of sample.cpp ========================== template<typename T> typename T::difference_type my_diff( T& v1, T& v2); template<typename T> T my_diff2(T& v1, T& v2); class A { public: A(int in = 5); typedef short difference_type; difference_type operator-(A&); }; int main() { A i(5); A j(10); my_diff(i,j); int x = 5; int y = 10; my_diff(x,y); return 0; } //====================== end of sample.cpp ========================== </pre> Какие проблемы может решить использование идиомы SFINAE в вышеприведённом коде?
<pre> //====================== start of sample.cpp ========================== template <typename T> struct remove_extend { typedef T type; }; template <typename T, std::size_t N> struct remove_extend<T[N]> { typedef T type; }; //====================== end of sample.cpp ========================== </pre> Что произойдёт если не определять специализированный шаблон remove_extend<T[N]> для массива??
<pre> //====================== start of sample.cpp ========================== class User { public: struct Region { short country_code; short city_code; static char* city_name; }; const char* name; int age; double balance; Region region; const char* get_name() const { return (*this).name; } int get_age() const { return this->age; } double get_balance() const { return (*this)->balance; } short get_country_code() const { return Region::country_code; } short get_city_code() const { return region.city_code; } const char* get_city_name() const { return Region::city_name; } }; //====================== end of sample.cpp ========================== </pre> В каких методах обращения к членам объекта класса user типа User корректны?
<pre> //====================== start of sample.cpp ========================== template<unsigned long N> class binary { public: static unsigned long const value = binary<N / 10>::value << 1 | N % 10; }; template<> class binary<0> { public: static unsigned long const value = 0; }; template<> class binary<1> { public: static unsigned long const value = 1; }; int main(int argc, char* argv[]) { static unsigned const x0 = binary<0>::value; static unsigned const x1 = binary<1000>::value; static unsigned const x2 = binary<1001>::value; static unsigned const x3 = binary<1010>::value; static unsigned const x4 = binary<1011>::value; return 0; } //====================== end of sample.cpp ========================== </pre> При инициализации какой переменной не будет использоваться конкретизация шаблона с параметром 0?
<pre> //====================== start of sample.cpp ========================== int main(int argc, char* argv[]) { const int a = 0; int b = 0; const int X = 0; int Y = 0; int Z = 0; auto lf1 = [&Y, Z, &a, &b, X] (double x) {return x > 0;}; return 0; } //====================== end of sample.cpp ========================== </pre> Значения каких переменным лямбда функция lf1 может изменить?
<pre> //====================== start of sample.h ========================== #include <algorithm> int main(int argc, char* argv[]) { size_t N = 40; int A[N]; size_t B[N*2]; char C[N]; int D[N]; std::replace(&B[0], &B[N/2], 0, 42); std::replace(C, (C+N+1), 'D', 'T'); std::copy(&A[0], &A[N-1], &D[0]); std::copy(A, (A+N), D); return 0; } //====================== end of sample.h ========================== </pre> В каких из вызовов обобщённых алгоритмов встроенные массивы С++ использованы без ошибок?
<pre> //====================== start of sample.cpp ========================== template<unsigned long N> class binary { public: static unsigned long const value = binary<N / 10>::value << 1 | N % 10; }; template<> class binary<0> { public: static unsigned long const value = 0; }; int main(int argc, char* argv[]) { static unsigned const xyz = binary<111>::value; return 0; } //====================== end of sample.cpp ========================== </pre> Конкретизация шаблона с значением 111 приводит: