C ++ два ключевых слова шаблона на одну функцию - PullRequest
0 голосов
/ 10 апреля 2020

Наблюдение 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);
      }

Google и различные ссылки на C ++ не помогли мне понять, что это значит, когда в строке два объявления template , Пожалуйста, помогите, кто знает.

1 Ответ

2 голосов
/ 10 апреля 2020

Это шаблон внутри шаблона.

Легче увидеть из объявления, которое, вероятно, выглядело примерно так

template<typename _IntType>
class geometric_distribution
{
    ...
    template<typename _UniformRandomNumberGenerator>
    result_type operator()(_UniformRandomNumberGenerator& __urng, const param_type& __param);
    ...
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...