has_arrow_operator type trait 模板
From: http://www.cnscn.org/htm_data/179/0805/14920.html
执行结果:
$ dync++ has_arrow_operator.cpp
0
1
1
0
不过对 B 使用的时候,编译器报错了, 怎么解决呢?
编译器: gcc (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/type_traits.hpp>
/* type trait : has_arrow_operator<T> */
template <typename T>
struct has_arrow_operator {
template <int> struct test;
template<typename U>
static boost::type_traits::yes_type check_sig(test<sizeof(&U::operator ->)>* = NULL);
template<typename U>
static boost::type_traits::no_type check_sig(...);
static const bool value = sizeof(check_sig<T>(0)) == sizeof(boost::type_traits::yes_type);
};
/* operator -> available */
class A {
public:
A* operator -> ();
};
/* operator -> hidden */
class B {
protected:
B* operator -> ();
};
/* operator -> not available */
class C {
};
int main() {
std::cout << has_arrow_operator<int>::value << std::endl;
std::cout << has_arrow_operator<boost::shared_ptr<int> >::value << std::endl;
std::cout << has_arrow_operator<A>::value << std::endl;
// ????? how to make this false
//std::cout << has_arrow_operator<B>::value << std::endl;
std::cout << has_arrow_operator<C>::value << std::endl;
}
执行结果:
$ dync++ has_arrow_operator.cpp
0
1
1
0
不过对 B 使用的时候,编译器报错了, 怎么解决呢?
编译器: gcc (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)
...全文
相关推荐
free-arrow:在Scala中实现Free Arrow的实现以及其他使用Arrows的有用工具
自由箭 在Scala中实现Free Arrow的实现以及其他使用Arrows的有用工具基于将的论文使用“自由箭头”构建一个计算图,该图可以解释为不同的执行上下文,并可以重用以从较小的上下文创建更复杂的
Rust_Study
**trait与泛型**:trait定义了一组方法签名,实现了trait的类型可以互相操作。泛型允许编写通用代码,减少代码重复。3.
CISP-CSE注册云安全工程师备考资源包基础教程
随着云计算技术的普及,云安全已成为网络安全领域的核心议题。CISP-CSE(注册云安全工程师)认证由中国信息安全测评中心颁发,旨在培养具备云安全专业知识和实践能力的实战型人才。本教程将结合"CISP-CSE注册云安全工程师备考资源包",系统性地为您梳理云安全的核心知识体系,并提供实战案例分析,助您高效备考。
绘图模拟:在冲动环境中固定时间的示例 附matlab代码.rar
绘图模拟:在冲动环境中固定时间的示例 附matlab代码.rar
基于规则的电动汽车混合能源管理系统,采用MATLAB、Simulink、Simscape Electrical和Stateflow。.zip
1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。


