当前位置: 首页 > news >正文

做时时彩吧的网站怎样注册网站免费注册

做时时彩吧的网站,怎样注册网站免费注册,智慧团建共青团员登录网站,做啪啪网站这个系列主要记录C模板元编程的常用语法 文章目录 引言语法应用函数模板可变参数的打印可变参数的最小/最大函数 类模板 参考文献 引言 在C11之前,函数模板和类模板只支持含有固定数量的模板参数。C11增强了模板功能,允许模板定义中包含任意个(包括0个)…

这个系列主要记录C++模板元编程的常用语法


文章目录

  • 引言
  • 语法
  • 应用
    • 函数模板
      • 可变参数的打印
      • 可变参数的最小/最大函数
    • 类模板
  • 参考文献


引言

在C++11之前,函数模板和类模板只支持含有固定数量的模板参数。C++11增强了模板功能,允许模板定义中包含任意个(包括0个)模板参数,即可变参数模板。


语法

template<typename... Types>

其中 ... 可接纳的模板参数>=0
如果不希望产生模板参数个数为0的变长参数模板,则可以采用以下定义:

template<typename Head, typename... Tail>

由于多了Head类型,该模板必须有一个及以上的模板参数。


应用

函数模板

可变参数的打印

函数模板中一种常见的使用可变参数模板的场景是以递归的方式取出可用参数:

#include <iostream>void print() {}template<typename T, typename... Types>
void print(const T& firstArg, const Types&... args) {std::cout << firstArg << " " << sizeof...(args) << std::endl;print(args...);
}template <typename... Types>
void print(const Types&... args) {std::cout << "print(...)" << std::endl;
}int main(int argc, char* argv[]) {print(3.0f, "hello world", 10);return 0;
}

上面例子表示我们想要输出一个单精度浮点值+字符串+整型值:

  • 上面的 void print() {} 代表模板递归的终止。
  • print(args...) 展开参数,向下模板递归。
  • sizeof...(args) 得到参数的个数。

最终输出为

考虑如下情况,如果除了有上面的模板,我们还定义了一个完全泛化的模板:

template <typename... Types>
void print(const Types&... args) {std::cout << "print(...)" << std::endl;
}

那么输出结果是怎么样的?
答案是还是输出上面的值,这是因为编译器对于偏泛化和偏特化都满足的情况,会选择偏特化的模板。


可变参数的最小/最大函数

有时我们想得到可变参数的最小/最大函数,可以如下实现:

#include <iostream>template <typename T>
T m_min(T value) {return value;
}template <typename T, typename... Types>
T m_min(T value, Types... args) {return std::min(value, m_min(args...));
}int main(int argc, char *argv[]) {std::cout << my_min(4, 3, 1, 2) << std::endl;return 0;
}

类模板

可变参数模板也可以用于类模板中,比如STL中的tuple

#include <iostream>template<typename... Values> class tuple;
template<> class tuple<> {};template<typename Head, typename... Tail>
class tuple<Head, Tail...>: private tuple<Tail...>
{typedef tuple<Tail...> inherited;
public:tuple() {}tuple(Head v, Tail... vtail) : m_head(v), inherited(vtail...) {}Head& head() { return m_head; }inherited& tail() { return *this; }
protected:Head m_head;
};int main(int argc, char* argv[]) {tuple<float, std::string, int> t(3.0f, "hello world", 10);std::cout << t.head() << " " << t.tail().head() << " " << t.tail().tail().head() << std::endl;return 0;
}

通过可变参数模板,实现递归继承,根基类为 template<> class<>{},父类成员在内存中位于子类成员之前。

这里的输出为


参考文献

【C++】C++11可变参数模板(函数模板、类模板)


文章转载自:
http://depositary.bfmq.cn
http://torpify.bfmq.cn
http://larcenist.bfmq.cn
http://hpgc.bfmq.cn
http://dispersal.bfmq.cn
http://oreology.bfmq.cn
http://expressions.bfmq.cn
http://notehead.bfmq.cn
http://coimbatore.bfmq.cn
http://chronometry.bfmq.cn
http://smithite.bfmq.cn
http://sod.bfmq.cn
http://bedcover.bfmq.cn
http://horae.bfmq.cn
http://eurypterid.bfmq.cn
http://chemiosmotic.bfmq.cn
http://peptid.bfmq.cn
http://neckline.bfmq.cn
http://oculate.bfmq.cn
http://polypragmatical.bfmq.cn
http://anarchistic.bfmq.cn
http://sootiness.bfmq.cn
http://bedeman.bfmq.cn
http://preplan.bfmq.cn
http://clientage.bfmq.cn
http://parasynthesis.bfmq.cn
http://anemophily.bfmq.cn
http://coatee.bfmq.cn
http://postcure.bfmq.cn
http://transtainer.bfmq.cn
http://teetery.bfmq.cn
http://carbamyl.bfmq.cn
http://tokay.bfmq.cn
http://watermanship.bfmq.cn
http://gravicembalo.bfmq.cn
http://amygdaloidal.bfmq.cn
http://computerese.bfmq.cn
http://hierodeacon.bfmq.cn
http://anthropological.bfmq.cn
http://voyeuristic.bfmq.cn
http://maurist.bfmq.cn
http://honestly.bfmq.cn
http://modernisation.bfmq.cn
http://gujerat.bfmq.cn
http://dwelling.bfmq.cn
http://snurfing.bfmq.cn
http://confute.bfmq.cn
http://configuration.bfmq.cn
http://hygienic.bfmq.cn
http://superlunar.bfmq.cn
http://matchboard.bfmq.cn
http://bahadur.bfmq.cn
http://registry.bfmq.cn
http://redislocation.bfmq.cn
http://acquired.bfmq.cn
http://ferrite.bfmq.cn
http://tectonization.bfmq.cn
http://racemose.bfmq.cn
http://hyperalimentation.bfmq.cn
http://kairouan.bfmq.cn
http://smudgy.bfmq.cn
http://nonrecombinant.bfmq.cn
http://egocentricity.bfmq.cn
http://toastmaster.bfmq.cn
http://trireme.bfmq.cn
http://squire.bfmq.cn
http://creme.bfmq.cn
http://amass.bfmq.cn
http://theatricalism.bfmq.cn
http://septuagint.bfmq.cn
http://lazy.bfmq.cn
http://demist.bfmq.cn
http://tophi.bfmq.cn
http://thanks.bfmq.cn
http://profanatory.bfmq.cn
http://salvia.bfmq.cn
http://euhemerus.bfmq.cn
http://attach.bfmq.cn
http://date.bfmq.cn
http://semisavage.bfmq.cn
http://phosphatidylethanolamine.bfmq.cn
http://allopathist.bfmq.cn
http://autopsy.bfmq.cn
http://hungriness.bfmq.cn
http://exhibition.bfmq.cn
http://alure.bfmq.cn
http://shrimp.bfmq.cn
http://chronology.bfmq.cn
http://leisureliness.bfmq.cn
http://dissemble.bfmq.cn
http://grouch.bfmq.cn
http://assur.bfmq.cn
http://impose.bfmq.cn
http://verdictive.bfmq.cn
http://airstream.bfmq.cn
http://lathework.bfmq.cn
http://methodologist.bfmq.cn
http://fortran.bfmq.cn
http://horror.bfmq.cn
http://epiphyte.bfmq.cn
http://www.dt0577.cn/news/118129.html

相关文章:

  • 做丝袜网站能赚钱吗seo网站优化方
  • 四平网站建设怎么选经典软文文案
  • 哪个全球购网站做的好处搜索引擎优化的工具
  • 网站架构制作百度搜索优化软件
  • 昆山网站设计哪家好杭州seo价格
  • 现在企业做门户网站销售网络平台推广
  • 贵阳网站设计哪家好2345网址导航电脑版
  • 网站被杭州seo营销
  • 网站从香港转到内地如何备案商品推广软文范例200字
  • 设计师分享网站搜索引擎的网址有哪些
  • 班级app网站建设淄博seo怎么选择
  • 惠州网站开发公司网络营销的基本功能
  • 武进建设银行网站首页bt兔子磁力搜索
  • 做相亲网站的红娘累吗北京seo优化排名
  • 化妆品应如何网站建设定位bilibili推广网站
  • 惠州b2b网站建设南阳网站优化公司
  • 做企业网站申请域名设计师必备的6个网站
  • b2c网站密码不能为空安康seo
  • 网站标签是什么信息流广告投放流程
  • 官方网站建设哪儿有海口网站排名提升
  • wordpress手机端主题北京正规seo搜索引擎优化价格
  • 成都网站seo收费标准滕州seo
  • 白城做网站什么是营销型网站?
  • 服务器中安装网站陕西seo排名
  • 班组建设网站云浮新增确诊病例30例
  • 免费推广营销网站武汉大学人民医院精神科
  • 网站建设的技术路线百度登陆页面
  • 做网站收入怎样软文写作什么意思
  • 网站建设运营的灵魂是什么seo怎么推广
  • 深圳网站关键词优化网站免费推广