草庐IT

some_trait

全部标签

c++ - 成员函数检测的递归type_traits

我正在尝试递归地应用type_traithas_fun以便C仅在T时启用其fun成员函数>有一个。有没有办法让C::fun被有条件地检测到?templatestructhas_fun{templateclasschecker;templatestaticstd::true_typetest(checker*);templatestaticstd::false_typetest(...);staticconstboolvalue=std::is_same(nullptr))>::value;};structA{voidfun(){std::coutstructC{voidfun(){st

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++ - pointer_traits 为既不是 X<A, T...> 也没有提供成员 typedef element_type 的类型提供什么?

下面的结果是什么?它是格式错误、未定义的行为还是定义良好且格式正确的行为?structA{};std::pointer_traitsx;我之所以问,是因为好奇想知道,也想知道任意类型是不是指针。我还想包括shared_ptr和friend。我想知道是否有类型特征(谓词),如果没有,我是否可以使用pointer_traits并检测是否声明了element_type。 最佳答案 它表示从20.6.3p1开始格式错误,因为它没有element_type并且不是类模板实例化typedefseebelowelement_type;Type:P

c++ - boost::container::allocator_traits::is_partially_propagable 是什么意思?

我很想理解boost::container::allocator_traits当我遇到boost::container::allocator_traits::is_partially_propagable时。我在网上找不到任何其他关于它的文档,我可以理解boost::container::allocator_traits除了is_partially_propagable和storage_is_unpropagable之外的所有其他成员。编辑:以及,它们是如何实现的以及在编写容器时如何使用它们? 最佳答案 它(is_partially

c++ - 在 std::operator << [With _Traits = std::char_traits<char> ] 中不匹配 'operator <<'

我有一个带有字符串转换运算符的Foobar类:#includeclassFoobar{public:Foobar();Foobar(constFoobar&);~Foobar();operatorstd::string()const;};我尝试这样使用它://C++源文件#include#include#include"Foobar.hpp"intmain(){Foobarfb;std::stringstreamss;ss我是否需要为Foobar显式创建一个运算符那么为什么会出现这个错误呢?我错过了什么?[编辑]我刚刚发现,如果我将发生错误的行更改为:ss编译成功。呃……!为什么编译器

c++ - 在嵌套的 lambda 中应用 function_traits 时编译失败

首先,我有这样的东西,一个重命名的function_traits来获取lambda的返回类型templatestructFuncAnalyzer{};templatestructFuncAnalyzer{usingTReturn=TRet;};templatestructFunctionAnalyzer:publicFuncAnalyzer{};然后当我在一个方法中有这个时,那个compi:autoa=[](constint&key)->QString{returnQString::number(key);};usingb=FunctionAnalyzer::TReturn;bx;但是

c++ - std::allocator_traits 默认为具有多个模板参数的分配器

std::allocator_traits当我提供一个带有单个模板参数的分配器的STL样式容器时,它会自动发挥它的魔力,但当我提供一个带有两个模板参数但其他方面相似的分配器的STL样式容器时,它不会自动发挥作用。我需要做什么来告诉std::allocator_traits如何与具有多个模板参数的分配器交互?是否有可能获得std::allocator_traits在这种情况下提供合理的默认值?例如,如果我采用HowardHinnant在AllocatorBoilerplate中提供的简单分配器并将其提供给std::vector那么一切都很好。如果我添加一个虚拟intallocator的参

c++ - char_traits<char16_t>::int_type 的大小不够大吗?

考虑以下程序:#include#include#includeintmain(int,char**){std::basic_stringstreamstream;stream.put(u'\u0100');std::cout输出是:Bad:0Bad:0Bad:1设置badbit的原因似乎是因为如果字符等于std::char_traits::eof(),'put'设置badbit。我现在不能再投入流中了。在http://en.cppreference.com/w/cpp/string/char_traits它指出:int_type:anintegertypethatcanholdallv

c++ - 我的 type_trait 在模板化/非模板化代码中的不同行为

在下面的代码片段中,has_bar在main和DoStuff方法中的行为不同:在main方法中,a_bar==false和b_bar==true。当我执行这个时,我得到2x“Foo”作为输出。为什么?#includestructA{voidFoo(){std::coutstructhas_bar:std::false_type{};templatestructhas_bar>:std::true_type{};templatevoidDoStuff(Tt){ifconstexpr(has_bar::value){t.Bar();}else{t.Foo();}}intmain(){Aa;

c++ - decltype(some_vector)::size_type 不能用作模板参数

下面的类不编译:template,classAllocator=std::allocator>classMyContainer{public:std::vectordata;std::vector>order;};我收到以下编译器错误:error:type/valuemismatchatargument2intemplateparameterlistfor‘templatestructstd::pair’为什么编译失败,而下面的代码工作正常?template,classAllocator=std::allocator>classMyContainer{public:std::vecto