/
niceSOFT
/
swig
Обзор
Документация
Войти
/
niceSOFT
/
swig
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Examples/test-suite/cpp14_variable_templates.i
26 строк
925 B
William S Fulton
Add cpp14_variable_templates testcase and document the support
10 май 2026, 19:37
10 май 2026, 19:37
2851c9b
Код
Авторство
О чём код?
%module cpp14_variable_templates // C++14 variable templates: a %template instantiation of one is wrapped as // a read only variable holding the value of the instantiated template. %inline %{ // Variable template parameterised on a type T - the typical use, mirroring // the std::*_v aliases in <type_traits>: a typed compile time constant // derived from properties of T. template<typename T> constexpr int bits_in = sizeof(T) * 8; // Variable template with a non-type integer parameter, holding the result // of a non-trivial compile time computation. Precomputing factorials at // compile time avoids the runtime recursion on every call. constexpr int compute_factorial(int n) { return n <= 1 ? 1 : n * compute_factorial(n - 1); } template<int N> constexpr int factorial = compute_factorial(N); %} %template(bits_in_char) bits_in<char>; %template(factorial_5) factorial<5>; %template(factorial_10) factorial<10>;