【发布时间】:2020-05-26 13:35:07
【问题描述】:
我有一个模板函数如下:
using namespace std::chrono;
using namespace std::chrono_literals;
template <typename D>
time_point<system_clock, D> makeTime(
int year, int month, int day, int hour = 0, int minute = 0,
int second = 0, int ms = 0, int us = 0, int ns = 0 );
通常,我这样称呼它:auto us_tp1 = makeTime<microseconds>( 2020, 5, 26, 21, 21, 21, 999, 123 );
但现在我需要通过别名“makeTimeUS”在某处调用它,如下所示:
auto us_tp1 = makeTimeUS( 2020, 5, 26, 21, 21, 21, 999, 123 );
就像 makeTimeUS 是 makeTime 的一个实例一样。
我试过了:
using makeTimeUS = template time_point<system_clock, microseconds> makeTime;
还有这个:
using makeTimeUS = template time_point<system_clock, microseconds> makeTime(
int, int, int, int, int, int, int, int, int );
但两者都无法通过编译。
如何实例化一个模板函数并同时为其赋予别名? 我需要这样做的原因是,调用 makeTimeUS 的旧代码太多,就好像它是普通函数而不是模板一样。 谢谢!
【问题讨论】:
标签: c++ templates alias instantiation using