我主要尝试编写std::array. 但是,我对聚合初始化的规则(以及其他一些小细节)不太满意,因此不想使用它。
我不喜欢聚合初始化的事情:
struct A { int x,y; };
std::array< A, 2 > arr{1,2,3};
// produces A[0].x = 1, A[0].y = 2, A[1].x = 1, A[1].y = 0
Run Code Online (Sandbox Code Playgroud)
class B { B() = delete; };
B{}; // no compile time error
Run Code Online (Sandbox Code Playgroud)
到目前为止我所拥有的是以下内容:
#include <cstddef>
#include <type_traits>
#include <utility>
template< typename T, typename ... Ts >
inline constexpr bool areT_v = std::conjunction_v< std::is_same<T, Ts> ... >;
namespace ttt {
template< typename T, int N >
struct …Run Code Online (Sandbox Code Playgroud) 我正在使用floats 在 Cuda 中进行计算。由于 GPU 上没有足够的内存,因此我们将原始数据存储在 GPU 上uint16_t。int16_t因此,在使用这些数据之前,我必须将其转换为floats。s的数量int并没有那么大(大约 12kuint16_t和 相同数量int16_t)。分析显示,转换数字需要相当长的时间(大约 5-10%)。其余的计算无法进一步优化。因此我的3+1问题是:
int将s 转换为s的最快方法是什么float。int16_t转换或.时是否有实质性差异uint16_t?int转换较大类型(例如int32或 )时是否存在实质性差异int64?floats 转换为ints. 这是人们通常不会做的事情吗?允许以下情况:
int * const p1 = nullptr;
auto p2 = static_cast< const int * const >( p1 );
Run Code Online (Sandbox Code Playgroud)
在我的理解中p1,是一个"const-ptr to int",它被转换为一个
"const-ptr to const-int"。
为什么以下内容被禁止
int * * const pp1 = nullptr;
auto pp2 = static_cast< const int * * const >( pp1 );
Run Code Online (Sandbox Code Playgroud)
在我的理解中,pp1“ const-ptr to ptr to int”应转换为“const-ptr to ptr to const-int”。因此我添加const,所以我认为这是允许的。