typetraits相关内容
这是我的一些实际代码,处理暴露C ++类到Lua,示例: #include #include //在实际代码中,许多这些C ++ Lua的堆栈辅助函数的特殊化。这里只是一个例子。 template T to(lua_State *,int); 模板 int to(lua_Stat
..
我试图做一个流操纵器的颜色使用输出到控制台。它的工作原理,改变文本和背景的颜色: std :: cout
..
在C ++ 11标准的细化过程中,似乎 is_trivially_destructible 被视为比更好/更一致的名称has_trivial_destructor 。 这是一个相对较新的开发,因为我的g ++ 4.7.1仍然使用旧的名称,它被固定为符合标准自4.8起: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52702 我一直懒地使
..
如同回答我的最后一个问题,建议在自动声明中使用 std :: common_type :: type 返回类型而不是我的原始 decltype()。但是,这样做遇到了问题(使用gcc 4.7.0)。考虑下面的简单代码 template A类; template A类{ X a [3]; template
..
请考虑以下示例 template class MyClass { public: double getValue() { // if“Type == void”return _x,if“Type!= void”return _y return(/ * SOMETHING * /)? (_x):(_y); } protected:
..
为了看看它是如何工作的,我看看 type_traits std :: common_type 的libstdc ++实现>。我不得不承认,我不真的明白它是如何工作的。这是: /// common_type template struct common_type; template struct comm
..
我要定义一个函数 template T constCast(const ScriptVar_t& s); 。根据 T ,我想要有不同的定义。 ( ScriptVar_t 是一个类,但在此上下文中的细节不重要。) T 不像特定类型那么简单,它们都是更复杂的静态布尔表达式。也就是说我有一个表达式的列表 ext1 .. extN ,对于每个,我有一个函数的定义。我想让它们
..
C ++运算子中的隐式类型转换规则 列出C ++的隐式类型转换。 所以问题是,是否有一个类型trait可以做那个表?类似于 的模板 struct promotion_type { typedef decltype(operator +(const T&,const J&))type; }; (不是我的问
..
在以下代码中声明迭代器i的正确方法是什么? #include #include using namespace std; template void f(const Mat& mat) { typedef typename Mat :: value_type :: iterator itr; /
..
对于这么简单的问题,很抱歉,但我找不到答案很容易。 Google对于“C ++ negation integral_constant”和类似的查询没有什么有趣的。 在C ++ 11中有任何特性使 std :: true_type 从 std :: false_type ,反之亦然?换句话说,我想要更多的readeble版本 std :: is_same
..
我有一个类( Voxel ),子类可能有或没有多个不同的属性(材质,密度等)与get和set方法。现在,我要写如下的一些代码: template void process(VoxelType voxel) { if(VOXEL_HAS_MATERIAL) { //做一些涉及调用get / setMaterial()的工作 } if(
..
我有一个泛型类有一个函数,我想限制在浮点类型的实例在编译时。如下例所示: 模板 class ClassName { //实例变量等。 void some_method() { // do stuff,but只适用于浮点类型 } } 拒绝使用some_method作为非浮点类型的ClassName? 我一直在查看SFI
..
考虑类模板,可以使用类型traits和dummy启用程序模板参数为某些类型的组提供模板特化。我已经早些时候询问。 现在,对于函数模板,我需要相同的东西:我有一个模板函数,想要一组类型的特殊化,例如,所有类型是一个类的子类型 X 。我可以用类型traits来表达这样的: std :: enable_if :: type
..
如何在不是字符串文字的地方可靠地static_assert? 例如,在下面的代码中,我试图包装标准assert宏,但静态拒绝不是字符串字面量的消息的任何东西(因为除非是字符串字面量,在assert触发器时不会在运行时显示)。 #include #include #include #define my_a
..
以下程序给我一个链接时间错误: #include
..
为了区分使用SFINAE的 T 类型的参数 t ,我想知道语句 QVariant :: fromValue(t); 和/或 QVariant :: value(); 编译。如果一个编译,另一个也是,除非你hack元类型系统。当且仅当 T 已使用 Q_DECLARE_METATYPE(T)声明。 非常简单的用法示例,其中想要通过
..
我尝试编写 is_iterator 类型特征。其中 T 是迭代器类型 is_iterator :: value == true ,否则为 is_iterator :: value == false 。 > template struct is_iterator:std :: false_type {}
..
源自此 CodeReview主题: #include #include #include #include #include template class aggregate_wrapper:public T { priv
..
读取一些源代码,我找到了下一个traits的定义: 命名空间dds { template struct topic_type_support {}; template struct topic_data_writer {}; template struct topic_data_reader {}; template
..
有没有办法检查序列容器是否在内存中是连续的?像: #include #include #include #include int main() { std :: cout
..