Как изменить количество аргументов шаблона, поддерживаемых в MSVC ++ std :: tuple? - PullRequest
2 голосов
/ 06 марта 2012

MSVC ++ еще не поддерживает шаблоны с переменными значениями, поэтому его стандартная библиотека «подделывает» их для классов типа std::tuple с помощью макросов.Недавно я попытался скомпилировать один из моих проектов с бета-версией VC11, и получил это, чтобы показать это:

gtest\gtest.h(9735): error C2977: 'std::tuple' : too many template arguments
c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(72) : see declaration of 'std::tuple'
gtest\gtest.h(9743): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14568): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14568): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14568): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14568): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(10076) : see declaration of 'testing::internal::ParamGeneratorInterface'
gtest\gtest.h(14570): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14581): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14581): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14586): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14586): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14593): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(14593) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>::Iterator' being compiled
gtest\gtest.h(14593): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14593): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(10003) : see declaration of 'testing::internal::ParamIteratorInterface'
gtest\gtest.h(14595): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14595): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14628): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14628): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14670): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14670): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14674): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14674): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14755): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14755): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14807): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14807): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14807): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14807): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
gtest\gtest.h(14809): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14821): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14821): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14826): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14826): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14833): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(14833) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::Iterator' being compiled
gtest\gtest.h(14833): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14833): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
gtest\gtest.h(14835): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14835): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14871): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14871): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14917): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14917): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14921): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14921): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(15007): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(15007): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(15289): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(15289): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(15289): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(15333): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(15333): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(15333): error C2955: 'std::tuple' : use of class template requires template argument list

Я слышал, что есть #define, который можно установить где-то, чтобы изменить этот параметр, ноЯ (на всю жизнь) не могу вспомнить, что это такое.Что это?

Ответы [ 3 ]

6 голосов
/ 06 марта 2012

Вы можете определить _VARIADIC_MAX для любого значения от 5 до 10 включительно.

Это и многие другие интересные факты о Visual C ++ 11 можно найти в статье MSDN « C ++ 11 Features (Modern C ++) ». Этот конкретный макрос обсуждается в разделе, озаглавленном «Искусственная вариация».

2 голосов
/ 06 марта 2012

Интересная цитата из blogs.msdn.com статья:

Faux variadics: Мы разработали новую схему для моделирования шаблонов variadic.Ранее в VC9 SP1 и VC10 мы неоднократно включали подзаголовки с макросами, каждый раз определяемыми по-разному, чтобы исключить перегрузки для аргументов 0, 1, 2, 3 и т. Д.(Например, неоднократно включали внутренний подзаголовок, чтобы исключить make_shared (args, args, args).) В VC11 подзаголовки исчезли.Теперь мы определяем сами шаблоны переменных как макросы (с большим количеством продолжений обратной косой черты), а затем расширяем их с помощью основных макросов.Это внутреннее изменение реализации имеет некоторые видимые для пользователя эффекты.Во-первых, код более удобен в обслуживании, более прост в использовании (добавление подзаголовков было довольно трудоемким) и немного менее ужасно нечитаем.Это то, что позволило нам легко реализовать вариативное расположение и должно облегчить устранение ошибок в будущем.Во-вторых, с отладчиком сложнее войти (извините!).В-третьих, у парного конструктора пары (piecewise_construct_t, tuple, tuple) были «интересные» эффекты.Это требует N ^ 2 перегрузок (если мы поддерживаем до 10 кортежей, это означает 121 перегрузку, поскольку здесь также учитываются пустые кортежи).Сначала мы заметили, что это (рассылка спама так много перегрузок парных кортежей плюс все перегрузки размещения) потребляло огромное количество памяти во время компиляции, поэтому в качестве обходного пути мы сократили бесконечность.В VC9 SP1 и VC10 бесконечность составляла 10 (т. Е. «Вариадные» шаблоны поддерживали от 0 до 10 аргументов включительно).В VC11 Developer Preview по умолчанию бесконечность равна 5.Это вернуло потребление памяти нашим компилятором к тому, что было в VC10. Если вам нужно больше аргументов (например, у вас был код, компилируемый с VC9 SP1 или VC10, который использовал 6 кортежей), есть аварийный люк.Вы можете определить _VARIADIC_MAX для всего проекта в диапазоне от 5 до 10 включительно (по умолчанию это 5). Увеличение этого значения заставит компилятор потреблять больше памяти и может потребовать от вас использования параметра / Zm, чтобы зарезервировать больше места для PCH.

1 голос
/ 14 января 2014

Это исправлено в редакции 675. Смотри https://code.google.com/p/googletest/source/detail?r=675

...