integral_constant

// from c++11 standard
namespace std {
template <class T, T v>
struct integral_constant {
static constexpr T value = v;
typedef T value_type;
typedef integral_constant<T,v> type;
constexpr operator value_type() { return value; }
};
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
}

————————————————
版权声明:本文为CSDN博主「csfreebird」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/csfreebird/article/details/44904121

#include <iostream>
#include <type_traits>

using namespace std;

//实现求阶乘
template<unsigned n>
struct fac : std::integral_constant<int, n*fac<n - 1>::value>{};
template<>
struct fac<0> : std::integral_constant<int, 1>{};

int main()
{
cout << fac<5>::value << endl;
return 0;
}

原文链接: https://www.cnblogs.com/xpylovely/p/12205375.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    integral_constant

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/192062

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午5:55
下一篇 2023年2月12日 下午5:55

相关推荐