База ответов ИНТУИТ

Программирование на С/С++

<<- Назад к вопросам

<pre> //====================== start of sample.cpp ========================== #include &lt;type_traits&gt; class A { public: A(int in = 5); }; int main() { std::true_type my_true; std::false_type my_false; return 0; } //====================== end of sample.cpp ========================== </pre> Какие утверждения о переменных my_true и my_false верны?

(Ответ считается верным, если отмечены все правильные варианты ответов.)

Варианты ответа
обе переменных принадлежат одной и той же иерархии классов
типы обеих переменных получены конкретизацией шаблона integral_constant(Верный ответ)
шаблонная функция, которая возвращает типы true_type или false_type в зависимости от параметров шаблона может использоваться для конкретизации другого шаблона(Верный ответ)
обе переменных содержат атрибуты true_value и false_value типа bool
Похожие вопросы
<pre> //====================== start of sample.cpp ========================== #include &lt;type_traits &gt; class A { public: A(int in = 5); }; int main() { std::is_pointer&lt;A&gt; is_ptr; return 0; } //====================== end of sample.cpp ========================== </pre> Как может использоваться объявление переменной is_ptr?
<pre> //====================== start of sample.cpp ========================== #include &lt;string&gt; #include &lt;type_traits&gt; struct my_string { std::string s; my_string(const std::string&amp; s); }; int main(int argc, char* argv[]) { is_copy_constructible&lt;my_string&gt;; return 0; } //====================== end of sample.cpp ========================== </pre> Каким образом можно проверить требование CopyConstructable посредством шаблона стандартной библиотеки is_copy_constructible для типа my_string из файла sample.cpp?
<pre> //====================== start of sample.cpp ========================== #include &lt;type_traits&gt; template &lt;typename IT_1, typename IT_2, bool b&gt; IT_2 copy_imp(IT_1 first, IT_1 last, IT_2 out, const std::integral_constant&lt;bool, b&gt;&amp;) { while(first != last) { *out = *first; ++out; ++first; } return out; } template &lt;typename T&gt; T* copy_imp(const T* first, const T* last, T* out, const std::true_type&amp;) { memmove(out, first, (last-first)*sizeof(T)); return out * (last-first); } template &lt;typename I1, typename I2&gt; inline I2 copy(I1 first, I1 last, I2 out) { typedef typename std::iterator_traits&lt;I1&gt;::value_type value_type; return copy_imp(first, last, out, std::has_trivial_assign&lt;value_type&gt;()); } class A {}; int main() { std::vector&lt;A&gt; vec1; std::vector&lt;A&gt; vec2; copy(vec1.begin(), vec1.end(), vec2.begin()); return 0; } //====================== end of sample.cpp ========================== </pre> Какие утверждения про то какая функция копирования copy_impl() будет использована верны?
<pre> //====================== start of sample.cpp ========================== #include &lt;climits&gt; #include &lt;limits&gt; #include &lt;boost/static_assert.hpp&gt; namespace name { BOOST_STATIC_ASSERT(std::numeric_limits&lt;int&gt;::digits == 32); } int main(int argc, char* argv[]) { return 0; } //====================== end of sample.cpp ========================== </pre> Что случится c программой из файла sample.cpp если в системе размер int больше 32 разрядов?
<pre> //====================== start of sample.cpp ========================== #include &lt;type_traits&gt; template &lt;typename IT_1, typename IT_2, bool b&gt; IT_2 copy_imp(IT_1 first, IT_1 last, IT_2 out, const std::integral_constant&lt;bool, b&gt;&amp;) { while(first != last) { *out = *first; ++out; ++first; } return out; } template &lt;typename T&gt; T* copy_imp(const T* first, const T* last, T* out, const std::true_type&amp;) { memmove(out, first, (last-first)*sizeof(T)); return out * (last-first); } template &lt;typename I1, typename I2&gt; inline I2 copy(I1 first, I1 last, I2 out) { typedef typename std::iterator_traits&lt;I1&gt;::value_type value_type; return copy_imp(first, last, out, std::has_trivial_assign<value_type>()); } class A {}; int main() { std::vector&lt;short&gt; arr1; std::vector&lt;short&gt; arr2; copy(arr1.begin(), arr1.end(), arr2.begin()); return 0; } //====================== end of sample.cpp ========================== </pre> Какие утверждения про используемую функцию копирования copy_impl() верны?
<pre> //====================== start of sample.cpp ========================== template &lt;typename T&gt; class multiplies: public binary_function&lt;T,T,T&gt; { public: T operator() (const T&amp; x, const T&amp; y) const { return x * y; } }; //====================== end of sample.cpp ========================== </pre> Какие утверждения про приведённый выше код функтора multiplies верны?
<pre> //====================== start of sample.cpp ========================== class ARef { public: ARef(A &amp;a, int i) : _a(a), _ix(i) {} ARef&amp; operator= (T t) { return *this;} operator T() {return _t;} operator A() {return _a;} A&amp; getA() { return _a;} bool operator == (A&amp; a) {return _a == a;} private: A&amp; _a; int _ix; T _t; }; class A { friend class ARef; public: A() {} ARef operator[] (int ix) {return ARef(*this, ix);} operator ARef() {return ARef(*this, ix);} }; int main() { A a; int i, j; T t; t = a[j]; return 0; } //====================== end of sample.cpp ========================== </pre> Какие из методов классов ARef и A из файла sample.cpp оказываются задействованы при операции t=a[j]?
<pre>//====================== start of sample.cpp ========================== #include &lt;vector&gt; class ServiceOrganization; class Building { static char* m_city; const unsigned int m_high_size; std::vector&lt;int&gt; m_flats; unsigned int m_square; ServiceOrganization&amp; m_organization; public: Building(); }; int main() { Building house; return 0; }//====================== end of sample.cpp ========================== </pre> Какие члены класса Building из файла sample.cpp обязательно должны быть инициализированы в списке инициализации?
<pre> //====================== start of sample.cpp ========================== int main(int argc, char* argv[]) { int a = 0; int b = 0; int X = 0; auto lf1 = [&amp;a,&amp;b,&amp;X] (int x) {return x &gt; 0;}; auto lf2 = [a,b] (int x) { x++; return x;}; auto lf3 = [=] (int x) { x++; return x;}; auto lf4 = [&amp;] (int x) { x++; return x;}; auto lf5 = [] (bool&amp; z) { z = !z; return;}; return 0; } //====================== end of sample.cpp ========================== </pre> Какие из приведённых в примере лямбда функций могут изменить значения переменных а и b?
<pre> //====================== start of sample.cpp ========================== class ARef { public: ARef(A &amp;a, int i) : _a(a), _ix(i) {} ARef&amp; operator= (T t) { return *this;} operator T() {return _t;} operator A() {return _a;} A& getA() { return _a;} bool operator == (A&amp; a) {return _a == a;} private: A&amp; _a; int _ix; T _t; }; class A { friend class ARef; public: A() {} ARef operator[] (int ix) {return ARef(*this, ix);} operator ARef() {return ARef(*this, ix);} }; //====================== end of sample.cpp ========================== </pre> Какие из методов класса ARef из файла sample.cpp являются необходимыми для поддержки идиомы контекстно-зависимой перегрузки операции индексирования агрегата?