草庐IT

out_of_range

全部标签

c++ - D3D11 : variable number of lights in HLSL

我正在使用C++和Direct3D11开发游戏引擎,现在我想向场景中添加可变数量的灯光。到目前为止,我设法添加和渲染了一些已知的并在着色器程序中编码的简单灯光。在shader.fx中:staticconstintLightsCount=4;structNF3D_LIGHT{//Members...};cbufferLight:register(b5){NF3D_LIGHTlight[LightsCount];};...//Andthepixelshaderfunction:float4PS(PS_INPUTinput):SV_Target{for(inti=0;i这很好用。但如果我尝试

c++ - 来自 Boost.Spirit 语法的属性:来自 std:vector of boost::variant 的错误

我有一个用于读取棋盘游戏位置描述的工作解析器(国际跳棋,officialgrammar):#include#includenamespacex3=boost::spirit::x3;autoconstcolon=x3::lit(':');autoconstcomma=x3::lit(',');autoconstdash=x3::lit('-');autoconstdot=x3::lit('.');autoconstking=x3::char_('K');autoconstcolor=x3::char_("BW");autoconstnum_sq=x3::int_;autoconstnu

c++ - range-v 3's ` partial_sum` 如何不与非拥有引用语义相矛盾?

考虑HowdoIwritearangepipelinethatusestemporarycontainers?.问题是如何使用一些给定的函数构建一个View来转换每个元素Tstd::vectorf(Tt);同时遵守therestriction(从那里的最佳答案借用)Aviewisalightweightwrapperthatpresentsaviewofanunderlyingsequenceofelementsinsomecustomwaywithoutmutatingorcopyingit.Viewsarecheaptocreateandcopy,andhavenon-owning

c++ - std::result_of 应用于 const 重载方法

如果我给typedefstd::vectorv;然后下面可以用来捕获常量迭代器的类型(另一种方法是使用v::const_iterator,但这取决于const_iterator成员类型在类中明确定义。typedeftypenamestd::result_of::typeconst_iterator;确实,我们可以检查上面的内容是否如我们所愿。static_assert(std::is_same::value);但是,我发现下面的编译器失败。typedeftypenamestd::result_of::typeiterator;编译器提示该方法被重载(通过const修饰符)并且无法明确解

c++ - range-v3 和 view_facade,不能为 ForwardRange 建模

这个简化的测试用例(按照用户手册中的示例编写)无法编译#include#includeusingv=std::vector;classrows:publicranges::view_facade{public:rows()=default;explicitrows(constv&data):it_(data.begin()),end_(data.end()){}private:friendranges::range_access;v::const_iteratorit_;v::const_iteratorend_;constint&read()const{return*it_;}boo

c++ - constexpr 算法 all_of 编译器错误

我有这么一小段代码:voidall_of_examples(){usingstd::begin;usingstd::end;//C++17//template//constexprboolall_of(InputItfirst,InputItlast,UnaryPredicatep);constexprautov2=std::array{1,1,1,1};constexprautoeqOne=[](intx)constexpr{constexprintone=1;returnx==one;};constexprboolisAllV2=std::all_of(begin(v2),end(

c++ - BOOST_FOREACH : What is the error on using this of a STL container?

有谁知道为什么以下会在VC9上产生错误?classElem;classElemVec:publicvector{public:voidfoo();};voidElemVec::foo(){BOOST_FOREACH(Elem&elem,*this){//Dosomethingwithelem}return;}我得到的错误是:errorC2355:'this':canonlybereferencedinsidenon-staticmemberfunctions我现在拥有的唯一(hack)解决方案是:voidElemVec::foo(){ElemVec*This=this;BOOST_FO

c++ - 模板 :Name resolution:Point of instantiation: -->can any one tell some more examples for this statement?

这是来自ISOC++标准14.6.4.1实例化点的声明Forafunctiontemplatespecialization,amemberfunctiontemplatespecialization,oraspecializationforamemberfunctionorstaticdatamemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecializationandthecontextfromwhichi

c++ - 我应该使用什么类型的迭代器差异来消除 "possible loss of data"警告?

我需要一个通用的x64模式警告规则。哪种方式更好?考虑以下几行代码constintN=std::max_element(cont.begin(),cont.end())-cont.begin();或constintARR_SIZE=1024;chararr[ARR_SIZE];//...constintN=std::max_element(arr,arr+ARR_SIZE)-arr;这是我常用的代码。我对x86没有任何问题。但是如果我在x64模式下运行编译器,我会收到一些警告:conversionfrom'std::_Array_iterator::difference_type'to

c++ - 使用 : Construction of objects at predetermined location in C++

在C++中在预定位置构造对象有什么用?以下代码说明了在预定位置的构造-void*address=(void*)0xBAADCAFE;MyClass*ptr=new(address)MyClass(/*argumentstoconstructor*/);这最终会在预定的“地址”处创建MyClass的对象。(假设address指向的存储足够大以容纳MyClass对象)。我想知道在内存中的这些预定位置创建对象的用途。 最佳答案 placementnew有用的一个场景是:您可以一次预分配大缓冲区,然后使用许多放置新运算符。这会给你更好的性能