草庐IT

is_constexpr_copiable

全部标签

c++ - MPL 序列 : is this legal? 的用户定义文字

能够将传递给文字运算符的字符串转换为MPL序列会很有用,因为这样我们就可以根据字符串的内容控制代码生成。以前,我认为这是不可能的,因为constexpr函数的参数在函数体内不被视为常量表达式。但是,我想出了以下在Clang3.4.2和GCC4.8.2下编译的解决方法:#include#include#includestructstring{constuintmax_tm_str[64];constsize_tm_length;templateconstexprstring(constTs...ts):m_str{(uintmax_t)ts...},m_length{sizeof...(

c++ - gcc 和 clang 不同意 constexpr 函数

从生成器函数编写一个简单的编译时std::array工厂,我偶然发现了这个:clang++3.5.1和g++4.9.2不同意函数是否是constexpr或不。代码(这是c++14!):#include#includetemplateconstexprstd::arraymake_array_impl(GenTypegen,std::index_sequence){return{{gen(I)...}};}templateconstexprstd::arraymake_array(GenTypegen){returnmake_array_impl(gen,std::make_index_

c++ - 扭曲的逻辑 : a global variable in one file refers to an extern variable but is also referred by that extern variable

文件A.cpp:#includeexternintiA;externintiB=iA;intmain(){std::cout文件B.cppexternintiB;externintiA=2*iB;编译链接运行,out进来debug和release模式是0,0我的问题是它是如何工作的,为什么在链接阶段没有问题?我正在使用VC++2003。 最佳答案 初始化程序覆盖了extern关键字,因此这没有什么“神奇”:您只是在不同的翻译单元中声明和定义两个完全不相关的变量。来自StandardforProgrammingLanguageC++-

解决报错:Can‘t connect to HTTPS URL because the SSL module is not available.

本人今天准备打开Pycharm安装一个label-studio包,试了很多次,接连报如下错误,因此我就去找了一些解决方案,现在总结如下:1、报错信息如下2、解决方案如下:github上有对应的解决方案,链接:https://github.com/conda/conda/issues/8273说的是D:\Anaconda3\DLLsssl.pydsearchfortheOpenSSLDLLsbutinthewrong/currentlocation,也就是D:\Anaconda3\DLLs文件夹下存在一个ssl.pyd文件,它在错误或者当前的目录上搜索OpenSSLDLL文件。但是这个目录下没有

c++ - Ctags 错误 "Is a directory"

我试图用ctags标记一个C++项目,并使用此答案C++sourcetagging中列出的选项.我在一个包含多个文件夹的项目树中,这些文件夹包含源文件。我尝试了以下方法来标记整个源代码树ctags--c++-kinds=+p--fields=+iaS--extra=+q--language-force=C++-R.find.-typef\(-iname"*.cpp"-o-iname"*.hpp"\)|xargsctags--c++-kinds=+p--fields=+iaS--extra=+q--language-force=C++ctags-R.ctags-R*和上面所有的都给出同样

c++ - 使用 c++ 11 constexpr 进行 std::map 初始化

我想用constexpr键初始化一个std::map。考虑以下C++11MWE:#includeusingstd::map;constexprunsignedintstr2int(constchar*str,constinth=0){return!str[h]?5381:(str2int(str,h+1)*33)^str[h];}constmapvalues={{str2int("foo"),"bar"},{str2int("hello"),"world"}};intmain(){return0;}当代码编译最近的clang和gcc时,生成的二进制文件将包含key类型的字符串:为什么k

c++ - Constexpr 替代 placement new 能够使内存中的对象保持未初始化状态?

我正在尝试创建一个静态容器,它具有基于堆栈的内存并且可以容纳T的N个实例。非常类似于std::vector我希望当前未使用的内存不包含T的初始化项。这通常可以通过placementnew来解决,但不可能在constexpr中使用。使用union我发现了一个技巧,您可以为此使用union,如下所示:templateunioncontainer_storage_type{structempty{};constexprcontainer_storage_type():uninitialized{}{}constexprcontainer_storage_type(value_typev):v

c++ - 与 friend 一起上课而不是前向声明,: which compiler is correct

这个问题在这里已经有了答案:Friendmethod"notdeclaredinthisscope"inC++(1个回答)Error:'FriendMemberFunctionName'wasnotdeclaredinthisscope(3个答案)关闭3年前。我有这个简单的C++程序:#includestructobj{friendintf(int);voidm(intx){std::cout如果我使用GNUC++编译器g++进行编译,我会得到错误prog.cpp:7:55:error:'f'wasnotdeclaredinthisscope但是,如果我使用cl(和/W4)编译它,它会

编译gcc踩坑记录——libtool: error: ‘/usr/local/lib/libgmp.la‘ is not a valid libtool archive

安装gcc依赖过程中出现错误,解决方法在google找到的。三个依赖如下:libgmplibmpfr依赖libgmplibmpc依赖libgmp、libmpfr直接就无脑(网上很多教程,这里就不赘述了)./configure--prefix=/home/xx/make&&makeinstall然后在libmpc时候就报错了:libtool:error:'/usr/local/lib/libgmp.la'isnotavalidlibtoolarchive解决方法:因为libmpc引用了libmpfr,libmpfr引用了libgmp而libgmp.la这个文件有bug,编译脚本里libtool路

c++ - constexpr 函数中的非 constexpr 调用

这是一个简化的代码示例,旨在生成任意值序列(在std::iota的意义上)和在它们之上的不同类别的迭代器:structdelta{templatevoidinc(I&i){++i;}templateInext(Ii){inc(i);returni;}};delta类有很多,每个类定义inc的方式不同,例如--i,i+=step,i-=step,i*=step,f(i)等函数next保持不变,实际上在基类中共享。我们正在从inc的变异操作中生成next的基于值的操作。做相反的事情是等价的,但是我们选择这种设计是为了性能,因为next只期望在某些初始化时被调用,而inc可能被调用一百万次。