如何实现声明功能-C 11,编译时间
How to implement decltype functionality - pre c++11, compile time
我有一个问题是否有办法实现cellettype关键字功能pre c 11。
我有一个简化的向量
template <class T>
struct MyVector {
typedef T ElementType;
T* arrayPtr;
uint64_t numberOfElements;
};
我希望能够在通用宏中获得T型T型,该宏可与此MyVector一起使用
#define ALLOCATE_SPACE(VectorRef, numberOfItems)
{
arrayPtr = new decltype(VectorRef)::ElementType[numberOfItems];
}
问题是我不能使用C 11东西。完美的解决方案是使其100%编译时间类型扣除。
任何人可以帮助我解决这个问题吗?
最好的问候
这是可能的。有一个提升宏来完成此魔术:
#include <boost/typeof/typeof.hpp>
#include <iostream>
#include <typeinfo>
int main() {
int a; float b;
BOOST_TYPEOF(a+b) c = a+b;
std::cout << typeid(c).name() << std::endl;
}
打印f
(浮点(。现场演示
不过,正如评论中已经指出的那样,您不需要这个问题。简单的模板功能将完成工作。
相关文章:
- 使用简单类型列表实现的指数编译时间.为什么
- 在已经使用Git的情况下减少编译时间
- C++常量数组的编译时间较长
- 编译时间文本到数字转换 (atoi)
- 在C++中执行 N 阶乘编译时间的 3 种不同/相同方法
- DLLexport 类模板实例(专用化),减少了仅标头模板库的编译时间
- 替换枚举以最大化编译时间检查的最佳方法
- 不同C++功能的编译时间
- 在预编译标头中实例化模板会缩短编译时间吗?
- 使用 SCons 提取每个编译单元的编译时间
- 将 lambda 函数转换为另一个编译单元中的普通函数会缩短编译时间吗?
- std :: Invoke_result_t编译时间语法错误
- 模板;constexpr;编译时间
- 如何实现声明功能-C 11,编译时间
- 如何减少编译时间:在包含未触及的头文件的情况下
- C++编译时间类型确定
- 特征:返回对具有编译时间尺寸检查的矩阵块的引用
- 在编译时间定义多个派生类
- 在编译时间创建查找表
- C 函数在编译时间返回类型