c++ - C++ 一个函数上的两个模板关键字
问题描述
观察random.tcc
STL 源文件发现以下算子定义:
template<typename _IntType>
template<typename _UniformRandomNumberGenerator>
typename geometric_distribution<_IntType>::result_type
geometric_distribution<_IntType>::
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __param)
{
// About the epsilon thing see this thread:
// http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html
const double __naf =
(1 - std::numeric_limits<double>::epsilon()) / 2;
// The largest _RealType convertible to _IntType.
const double __thr =
std::numeric_limits<_IntType>::max() + __naf;
__detail::_Adaptor<_UniformRandomNumberGenerator, double>
__aurng(__urng);
double __cand;
do
__cand = std::floor(std::log(1.0 - __aurng()) / __param._M_log_1_p);
while (__cand >= __thr);
return result_type(__cand + __naf);
}
谷歌和各种 C++ 参考资料并没有帮助我理解template
连续有两个声明时的含义。请知道的人帮忙。
解决方案
它是模板中的模板。
从可能看起来像这样的声明中更容易看到
template<typename _IntType>
class geometric_distribution
{
...
template<typename _UniformRandomNumberGenerator>
result_type operator()(_UniformRandomNumberGenerator& __urng, const param_type& __param);
...
};
推荐阅读
- java - (JAVA) 为我的自动售货机执行 while 循环
- android - 如何在 SharedPreference 中存储日期?
- python - TypeError:'NoneType' 对象不可下标 opencv-python / python face_recognition
- c# - 来自系统帐户服务的用户模拟
- c++ - aws-sdk-cpp - 在 Ubuntu 中未定义对 Aws::InitAPI 的引用
- oracle12c - Oracle删除查询优化
- .net - NEST 7:如何获取每个文档的出现次数?
- php - 在多个 WP 插件中使用相同的代码部分
- mysql - 使用spring security添加用户和角色时无法解决sql异常问题
- reactjs - Grafana Plugin - 如何从反应插件中删除指标面板