草庐IT

uniform-initialization

全部标签

c++ - gcc 4.8 中静态 constexpr 成员数组的初始化

当使用-std=c++11时,以下代码在gcc4.9.1和clang-3.6中编译和运行:structBar{intx;};structFoo{staticconstexprBarbars[]={1,2,3};};constexprBarFoo::bars[];但是在gcc4.8.3中失败,导致报错./cpptest.cpp:14:43:error:couldnotconvert'1'from'int'to'constBar'staticconstexprBarbars[]={1,2,3};^./cpptest.cpp:14:43:error:couldnotconvert'2'fro

c++ - 通过枚举值构造initializer_list包含随机值

在思考问题std::initializerlistfromalreadyexistingstd::arraywithoutenumeratingeachelement的解决方案时,我开发了与bolov类似的机制做了,但不是构造对象,而只是构造器列表。令我惊讶的是我的解决方案不起作用,我也不知道为什么。#include#include#includetemplatestd::initializer_listarray_to_init_list_helper(std::arrayarr,std::index_sequence){return{arr[Is]...};}templatestd

c++ - std::array initializer list 在初始化列表中初始化

虽然我非常喜欢C++11中的新特性,但有时我觉得我遗漏了它的一些微妙之处。初始化int数组工作正常,初始化Element2vector工作正常,但初始化Element2数组失败。我认为正确的语法应该是未注释的行,但对我来说没有任何初始化尝试成功。#include#includeclassElement2{public:Element2(unsignedintInput){}Element2(Element2const&Other){}};classTest{public:Test(void):Array{{4,5,6}},Array2{4,5},//Array3{4,5,6}Array

c++ - 是否可以确保仅在 'static initialization' 步骤期间调用函数

我想知道是否有可能确保一个函数只在程序的静态初始化步骤中被调用?举个例子,假设我有一些包含std::map对象并公开了insert和at方法的单例类它的。我想确保从中读取数据(at方法)是线程安全的,据我所知,这需要确保没有任何内容正在修改数据(即使用insert方法)。映射旨在仅在静态初始化期间填充,此时我假设只有一个线程。有什么方法可以确保在main()开始后,不会有被误导的用户调用insert吗?示例代码#include#includeclassSingleton{private:std::mapm_map;public:staticSingleton&instance(){st

c++ - 如何统一初始化 unique_ptr 的映射?

我有这段代码可以将映射从into初始化为unique_ptr。autoa=unique_ptr(newA());map>m;m[1]=move(a);我可以使用统一初始化吗?我试过了map>m{{1,unique_ptr(newA())}};但是我得到了一个错误。错误信息的一部分是Ininstantiationof'std::_Rb_tree_node::_Rb_tree_node(_Args&&...)[with_Args={conststd::pair>>&};_Val=std::pair>]':...Infileincludedfrom/opt/local/include/gcc

c++ - GLSL : Replace large uniform int array with buffer or texture

现在我正在尝试将一个整数数组传递到片段着色器中,并通过一个统一数组来实现:uniformintmyArray[300];并在着色器外用glUniform1iv填充它。不幸的是,大于~400的统一数组会失败。我知道我可以改用“统一缓冲区”,但似乎找不到将大型一维数组传递到带有缓冲区或其他方式的片段着色器的完整示例。谁能提供这样的例子? 最佳答案 这应该让您开始使用统一缓冲区对象来存储数组。注意GL要求UBO的最小容量为16KiB,最大容量可以通过GL_MAX_UNIFORM_BLOCK_SIZE查询。片段着色器示例(UBO需要Open

c++ - 错误 C2360 : Initialization of 'hdc' is skipped by 'case' label

下面两个定义的巨大差异在哪里,会产生错误C2360?switch(msg){caseWM_PAINT:HDChdc;hdc=BeginPaint(hWnd,&ps);//Noerrorbreak;}和switch(msg){caseWM_PAINT:HDChdc=BeginPaint(hWnd,&ps);//Errorbreak;} 最佳答案 第一个是合法的,第二个不是。有时允许跳过没有初始化器的声明,但绝不允许有初始化器的声明。参见Storageallocationoflocalvariablesinsideablockinc++

c++ - 为什么 g++5 在自动类型推导中推导对象而不是 initializer_list

我最近发现了这段代码:structFoo{};intmain(){Fooa;//clang++deducesstd::initializer_list//g++5.1deducesFooautob{a};a=b;}它在g++5.1中编译良好,但在clang++中失败(同时使用-std=c++11和-std=c++14,结果相同)。原因是clang++deducesthetypeofbasstd::initializer_list,而g++5.1deducesasFoo.AFAIK,类型确实应该是(确实违反直觉)std::initializer_list这里。为什么g++5将类型推断为F

Hadoop:DataNode启动失败:Initialization failed for Block pool

一、问题发现​在启动Hadoop集群后,发现原本应该是启动三台机子的数据节点,结果只有一台node2成功启动,另外两台(node1、node3)并没有启动,如下两图所示:问题描述:​确认配置信息没问题后,查看Hadoop下hdfs目录中的DataNode日志(配置文件中指定,比如笔者安装Hadoop所在路径为/export/server/hadoop/logs/hdfs),DataNode的日志文件为:cat该文件发现:ERRORorg.apache.hadoop.hdfs.server.datanode.DataNode:InitializationfailedforBlockpoolreg

c++ - clang 中的别名 std::initializer_list

我想使用std::initializer_list的别名来代替它本身:#includetemplateusingInitializerList=std::initializer_list;//note:candidatetemplateignored:couldn'tinfertemplateargument'T'templatevoidf(InitializerListlist){}intmain(){//error:nomatchingfunctionforcallto'f'f({1,2,3,4,5});}该代码使用gcc&cl没问题。但是,使用clang我得到一个错误::11:3