草庐IT

-std=gnu99

全部标签

c++ - 检测某些非数字类型 T 的 std::numeric::type<T> 的特化

我想检查一个类型是否在std::numeric_limits中有一个条目。当类型是一个数组时——(或者可能不是一个数字?)我得到一个编译器错误。这使我无法根据std::numeric_limits是否支持该类型来检测和分支。如果有人愿意分享任何见解,我将不胜感激。//thefollowingprovokescompilererroronClang//Functioncannotreturnarraytype'type'(aka'char[20]')static_assert(!std::numeric_limits::is_specialized,"!std::numeric_limi

c++ - C++17 中 std::unordered_map 的推导指南

我已经通过使用cppreference阅读了C++17中std::unordered_map的推导指南.然后尝试运行以下从cppreference复制的示例。#includeintmain(){//std::unordered_mapm1={{"foo",1},{"bar",2}};//Error:braced-init-listhasnotype//cannotdeducepairfrom//{"foo",1}or{"bar",2}std::unordered_mapm1=std::initializer_list>({{"foo",2},{"bar",3}});//guide#2s

c++ - std::unique 没有等价关系的例子(去掉连续的空格)

cppreference上有一个例子关于如何使用std::unique从字符串中删除连续空格:std::strings="wannagotospace?";autoend=std::unique(s.begin(),s.end(),[](charl,charr){returnstd::isspace(l)&&std::isspace(r)&&l==r;});//snowholds"wannagotospace?xxxxxxxx",where'x'isindeterminatestd::cout但是,在唯一性的要求部分中指出Elementsarecomparedusingthegiven

c++ - 在库的公共(public) API 中从 std::string、std::ostream 等过渡

对于具有相同二进制文件的多个工具链之间的API/ABI兼容性,它是wellknownthatSTL容器、std::string和其他标准库类(如iostreams)在公共(public)header中禁止。(异常(exception)情况是,如果一个人为每个版本的受支持工具链分发一个构建;一个人提供没有二进制文件的源代码供最终用户编译,这在当前情况下不是首选选项;或者一个人内联转换为其他容器,以便不同的std实现不会被库吸收。)如果一个人已经有一个不遵循此规则的已发布库API(请friend),那么最好的前进道路是什么,同时保持尽可能多的向后兼容性,并尽可能地支持编译时中断'吨?我需要

c++ - 如果 count() 是 constexpr 函数,为什么 std::array<int, count()> 不能编译?

这个问题在这里已经有了答案:constexprnotworkingifthefunctionisdeclaredinsideclassscope(3个回答)3年前关闭。为什么下面的C++代码不能用VC2017编译?structFixedMatchResults{staticconstexprstd::size_tcount(){return20;};std::arrayresults;};错误是:errorC2975:'_Size':invalidtemplateargumentfor'std::array',expectedcompile-timeconstantexpression

c++ - std::string 类继承和繁琐的 C++ 重载解析

我需要扩展std::basic_string来处理路径字符串和不同的operator+:#includetemplateclasspath_basic_string:publicstd::basic_string{public:usingbase_type=std::basic_string;path_basic_string()=default;path_basic_string(constpath_basic_string&)=default;path_basic_string&operator=(constpath_basic_string&)=default;path_basi

c++ - constexpr 中的 std::variant 修改

考虑以下两个程序:#include#includeconstexprautof(){usingT=std::variant;Tt(false);t=T(true);returnstd::get(t);}templatevoidprint(){std::cout();}和#include#includeconstexprautof(){usingT=std::variant;Tt(false);t=T(42);returnstd::get(t);}templatevoidprint(){std::cout();}GCC编译这两个并输出预期的结果。在这两种情况下,Clang都不会编译它们中

c++ - 在 C++03 中返回类似 `std::auto_ptr` 的集合的最佳方法是什么?

std::auto_ptr不允许存储在STL容器中,例如std::vector.但是,偶尔会出现需要返回多态对象集合的情况,因此无法返回对象vector(由于切片问题)。我可以使用std::tr1::shared_ptr并将它们粘贴在vector中,但随后我不得不为维护单独的引用计数付出高昂的代价,并且拥有实际内存(容器)的对象在逻辑上不再“拥有”这些对象,因为它们可以在不考虑所有权的情况下从中复制出来。C++0x以std::vector>的形式为这个问题提供了完美的解决方案。,但我无权访问C++0x。一些其他注意事项:我无法访问C++0x,但我可以使用TR1。我想避免使用Boost(

C++0x |为什么 std::atomic 使用 volatile-qualifier 重载每个方法?

当前草案的以下摘录说明了我的意思:namespacestd{typedefstructatomic_bool{boolis_lock_free()constvolatile;boolis_lock_free()const;voidstore(bool,memory_order=memory_order_seq_cst)volatile;voidstore(bool,memory_order=memory_order_seq_cst);boolload(memory_order=memory_order_seq_cst)constvolatile;boolload(memory_orde

c++ - std::map::emplace() 缺失 - 过时的库?

我正在尝试使用map的C++11emplace()函数,但NetBeans说map没有这样的函数。查看header,它是“正确的”——没有提及(在Fedora16上)emplace()。这一切都很好,你知道……但我有点想使用emplace()。如何启用此功能?我知道它自去年三月以来就存在,可能更早。彻底的搜索表明emplace()基本上只存在于我的系统中的列表和vector的标题中。由于近十年来C++没有重大修订,所以我没有运气找到有关如果库“错误”该怎么办的文档。 最佳答案 如果您的实现不支持某些功能,您有两种选择:不要使用该功能