编译时单例多于一次实例化检测 [英] Compile-time singleton more-than-one-time-instantiation detection

查看:32
本文介绍了编译时单例多于一次实例化检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建一个模板元构造,该构造元可以在第一次(或前n次)调用时执行一条执行路径,而在一次以上(然后n次)调用时执行另一条执行路径?

Is it possible to create a template meta construction that can take one execution path first time (or first n times) it is called and another execution path if it is called more than once (more then n times)?

推荐答案

否。模板仅在编译时评估。

No. Templates are evaluated at compile time only.

问题在于运行时发生的事情(执行路径)。

现在应该可以在代码中构建此构造了,但它不是模板元结构(尽管它可以是模板元程序的一部分,但是进行测试的代码将是运行时代码(即普通代码)。)

The question is about things that happen at run-time (execution path).
Now it should be very possible to build this construct in code, but it is not a template meta-construct (though it can be part of a template meta-program, but the code that does the test will be runtime code (ie normal code)).

这篇关于编译时单例多于一次实例化检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆