模板函数调用
来源:互联网 发布:网络服务器机柜回收 编辑:程序博客网 时间:2024/06/08 14:08
2 template <typename Service>
3 bool has_service() const
4 {
5 boost::asio::detail::mutex::scoped_lock lock(mutex_);
6
7 boost::asio::io_service::service* service = first_service_;
8 while (service)
9 {
10 if (service_id_matches(*service, Service::id))
11 return true;
12 service = service->next_;
13 }
14
15 return false;
16 }
bool has_service(io_service& ios)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<io_service::service*>(static_cast<Service*>(0));
(void)static_cast<const io_service::id*>(&Service::id);
return ios.service_registry_->template has_service<Service>();
}
下面是测试例子,在VS2005中编译通过。原来,函数使用的时候,可以完全指定模板函数定义。
2 {
3 public:
4 static int getI()
5 {
6 return 100;
7 }
8 };
9 class V
10 {
11 public:
12 template<class K>
13 void PrintK()
14 {
15 cout<<K::getI()<<endl;
16 }
17 };
18 void m()
19 {
20 V v;
21 v.template PrintK<VV>();
22 }
ANSI C++ '03
14.2 Names of template specializations
4 When the name of a member template specialization appears after . or -> in a postfix-expression, or after
nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a
template-parameter (14.6.2), the member template name must be prefixed by the keyword template.
Otherwise the name is assumed to name a non-template. [Example:
class X {
public:
template<size_t> X* alloc();
template<size_t> static X* adjust();
};
template<class T> void f(T* p)
{
T* p1 = p->alloc<200>();
// ill-formed: < means less than
T* p2 = p->template alloc<200>();
// OK: < starts template argument list
T::adjust<100>();
// ill-formed: < means less than
T::template adjust<100>();
// OK: < starts template argument list
}
- 调用函数模板排序
- 模板函数调用
- 函数模板的调用
- 模板函数的调用困惑
- 函数模板重载调用顺序
- 模板函数的嵌套调用
- WP模板常用调用函数
- 【ThinkPHP学习】模板函数调用
- wordpress模板调用函数get_template_part()
- Smarty模板中调用PHP函数
- 类模板成员函数的调用问题
- 关于函数模板重载的调用顺序
- 非成员模板函数,混合式调用问题
- 8086汇编语言 调用函数的模板
- 模板间调用成员函数指针
- 通过模板类对象操作调用函数
- 调用模板类的模板成员函数的问题
- C++函数模板的显示调用与隐式调用
- linux 删除apache
- Apache HTTP Server 与 Tomcat 的三种连接方式介绍
- linux通过ssh登录其他服务器,不用输入密码
- javascript验证URl地址
- 使用windbg抓取崩溃文件和分析的过程
- 模板函数调用
- XDebug 配置与使用,WinCacheGrind 查看
- test3.1
- ubuntu kernel编译
- 免费的编程中文书籍索引【收藏速度】
- Sqlserver 批量提交的方案改进!
- iOS KeyChain
- HTML5判断移动端横屏竖屏功能
- Foundation框架--NSString类字符串常用操作