<pre> //====================== start of sample.cpp ========================== #include <string> #include <type_traits> struct my_string { std::string s; my_string(const std::string& s); }; int main(int argc, char* argv[]) { is_copy_constructible<my_string>; return 0; } //====================== end of sample.cpp ========================== </pre> Каким образом можно проверить требование CopyConstructable посредством шаблона стандартной библиотеки is_copy_constructible для типа my_string из файла sample.cpp?
<pre> //====================== start of sample.cpp ========================== #include <boost/shared_ptr.hpp> #include <boost/scoped_ptr.hpp> #include <boost/weak_ptr.hpp> #include <vector> struct A { virtual ~A(); }; struct B: public A {}; struct C {}; void foo1(boost::scoped_ptr<A> a); void foo2(boost::scoped_ptr<B>& a); void foo3(boost::shared_ptr<C> a); void foo4(boost::scoped_ptr<A>* a); void foo5(std::vector< boost::scoped_ptr<C> >& c); int main(int argc, char* argv[]) { boost::scoped_ptr<A> b1(new A); boost::scoped_ptr<B> b2(new B); boost::scoped_ptr<C> b3(new C); boost::scoped_ptr<A> b4; std::vector< boost::scoped_ptr<C> > v1; v1.push_back(b3); foo1(b1); foo2(b2); foo3(b3.lock()); foo4(&b4); foo5(v1); return 0; } //====================== end of sample.cpp ========================== </pre> В каких из функциях умный указатель boost::scoped_ptr используется правильно?
<pre> //====================== start of sample.cpp ========================== #include <boost/circular_buffer.hpp> int main(int argc, char* argv[]) { boost::circular_buffer<int> circ(3); circ.push_back(1); circ.push_back(2); circ.push_back(3); circ.push_back(4); circ.push_back(5); circ.pop_back(); return 0; } //====================== end of sample.cpp ========================== </pre> Какие значения останутся в циклическом буфере circ в примере в файле sample.cpp?
<pre> //====================== start of sample.cpp ========================== #include <boost/shared_ptr.hpp> #include <boost/scoped_ptr.hpp> #include <boost/weak_ptr.hpp> #include <vector> struct A { virtual ~A(); }; struct B: public A {}; struct C {}; void foo1(boost::shared_ptr<A> a); void foo2(boost::weak_ptr<B>& a); void foo3(boost::shared_ptr<C> a); void foo4(boost::scoped_ptr<A>& a); void foo5(std::vector< boost::weak_ptr<C> >& c); int main(int argc, char* argv[]) { boost::shared_ptr<A> a(new A); boost::shared_ptr<B> b(new B); boost::shared_ptr<C> c(new C); boost::weak_ptr<A> b1(a); boost::weak_ptr<B> b2(b); boost::weak_ptr<C> b3(c); std::vector< boost::weak_ptr<C> > v1; v1.push_back(b3); foo1(b2.lock()); foo2(b2); try { boost::shared_ptr<C> c1(c); foo3(c1); } catch(boost::bad_weak_ptr& e) { } foo4(b2.lock()); foo5(v1); return 0; } //====================== end of sample.cpp ========================== </pre> Вызовы каких функций выполнены корректно и операции создания их параметров не содержат очевидных проблем?
<pre> //====================== start of sample.cpp ========================== #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> #include <vector> struct A { virtual ~A(); }; struct B: public A {}; struct C {}; void foo1(boost::shared_ptr<A>& a); void foo2(boost::shared_ptr<A const> a); void foo3(boost::shared_ptr<B>& a); void foo4(boost::shared_ptr<const A> a, boost::shared_ptr<C> c); void foo5(std::vector< boost::shared_ptr<C> >& c); int main(int argc, char* argv[]) { boost::shared_ptr<A> b1(new A); boost::shared_ptr<B> b2(new B); boost::shared_ptr<C> b3(new C); boost::weak_ptr<A> b4(b1); std::vector<boost::shared_ptr<C>> v1; v1.push_back(b3); foo1(b1); foo2(b2); foo3(b3); foo4(b4.lock(), b3); foo5(v1); return 0; } //====================== end of sample.cpp ========================== </pre> Вызовы каких функций выполнены корректно и операции создания их параметров не содержат очевидных проблем?
<pre> //====================== start of sample.cpp ========================== #include <boost/variant/variant.hpp> struct A {}; struct B { B(int src); private: B(const B& src); }; struct C { C(int src); private: C(); }; struct D {}; int main(int argc, char* argv[]) { boost::variant<int, A, B, C> myvariant; int x; int* y; A a; B b(x); C c(x); D d; myvariant = x; myvariant = y; myvariant = a; myvariant = b; myvariant = c; myvariant = d; return 0; } //====================== end of sample.cpp ========================== </pre> Какие объекты можно присвоить объекту myvariant из примера в файле sample.cpp?
<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 ========================== #include <algorithm> #include <vector> int main(int argc, char* argv[]) { std::vector<int> v1; auto lf1 = [] (int x) {return x > 0;}; auto lf3 = [] (int& x) { x++; return;}; auto lf5 = [] (bool& z) { z = !z; return;}; int cnt1 = std::count_if(v1.begin(), v1.end(), lf1); int cnt2 = std::count_if(v1.begin(), v1.end(), [] (int x) -> bool {return x+1;}); int cnt3 = std::count_if(v1.begin(), v1.end(), lf3); int cnt4 = std::count_if(v1.begin(), v1.end(), [] (int x, int& y) -> double {return x+y;}); int cnt5 = std::count_if(v1.begin(), v1.end(), lf5); return cnt1; } //====================== end of sample.cpp ========================== </pre> При вычислении каких переменных лямбда-функции в алгоритме count_if используются корректно?
<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.cpp ========================== #include <vector> class ServiceOrganization; class Building { static char* m_city; const unsigned int m_high_size; std::vector<int> m_flats; unsigned int m_square; ServiceOrganization& m_organization; public: Building(); }; int main() { Building house; return 0; }//====================== end of sample.cpp ========================== </pre> Какие члены класса Building из файла sample.cpp обязательно должны быть инициализированы в списке инициализации?