草庐IT

is_function

全部标签

c++ - 如何解释 is_assignable 中的 declval<_Dest>() = declval<_Src>()

我想弄清楚如何在is_assignable的实现中解释declval()=declval()。declval将类型转换为引用。鉴于此,我将表达式转换为以下四种可能性之一:_Dest&&=_Src&&_Dest&&=_Src&_Dest&=_Src&&_Dest&=_Src&然后我创建了两个辅助函数。templateTrvalue();templateT&lvalue();我的理解是这四个表达式可以用模板函数实现。_Dest&&=_Src&&----->右值()=右值()其他三个也是一样。然后我通过编译三对具体类型的每种可能性的模板函数版本来模拟decltype(declval()=de

c++ - 米斯拉-C++ :2008[8-4-3] : return in all exit path in function

在测试我的代码(静态分析)以查看我是否尊重misrac++2008时,我收到以下错误Functiondoesnotreturnavalueonallpaths.函数看起来像int*Dosomething(stringv){int*retvalue=NULL;if(0==exists(v)){throw("error:valuedoesn'texist");}else{retvalue=dosomecomputations(v);}returnretvalue;}我真的需要抛出一个异常,因为调用者应该根据错误做一些事情。可能的错误列表可能很大,而且不仅仅是该代码示例中的值不存在。我该如何

c++ - "static functions with block scope are illegal"错误取决于初始化样式?

我有一个类Library,其中包含一个结构Transaction,该结构有一个类型为Patron的成员变量。classPatron{public:Patron(){}};classLibrary{public:structTransaction{Patronp;Transaction(Patronpp):p(pp){}Transaction();};};对于Transaction的默认构造函数,我有一个函数default_transaction()返回对静态对象的const引用,正如Stroustrup在“编程-原则和实践”中所推荐的使用C++”(第324页);推理:避免在构造函数代码

c++ - std::is_class 的实现

我想知道std::is_class(http://www.cplusplus.com/reference/type_traits/is_class/)是如何实际实现的。我查看了/usr/include/c++/4.8/tr1/type_traits但似乎唯一存在的是:///is_classtemplatestructis_class:publicintegral_constant{};__is_class的定义在任何地方都找不到(或者我只是看得不够深入)。无论如何,如果有人能指出我在哪里寻找这个(以及std命名空间中的其他is_***),我会很高兴 最佳答案

c++ - 在 Visual Studio 中构建解决方案时出现 "Unable to create directory"错误 "Access to path is denied."

我正在尝试在VS2013中构建一个VS2010C++项目(准确地说,是来自SteinbergVstSDK的示例项目)并出现以下错误:C:\ProgramFiles(x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(1235,5):errorMSB3191:Unabletocreatedirectory"C:\ProgramFiles(x86)\CommonFiles\VST3\Steinberg".Accesstothepath'C:\ProgramFiles(x86)\CommonFiles\VST3\St

c++ - 允许这种派生到基础转换的理由是什么(当它似乎违反 IS-A 时)?

我用来快速确定派生到基础的转换是否合法的规则是检查在转换的上下文中,derived是否是一个base(即,derived提供对base的公共(public)API的访问)。它在C++Primer(第5版)中更好地表述为:Foranygivenpointinyourcode,ifapublicmemberofthebaseclasswouldbeaccessible,thenthederived-to-baseconversionisalsoaccessible,andnototherwise.现在让我们想象一个类层次结构如下:classBase{public:intmem;};clas

c++ - 将 std::function 绑定(bind)到不同对象实例的相同函数

是否可以重新绑定(bind)std::function以指向相同的函数但具有不同的对象实例?如果我有一个对象,它有一个绑定(bind)到另一个函数的std::function,但是如果那个对象被复制到另一个实例,我想将std::function重新绑定(bind)到那个新实例而不是旧实例。#include"stdafx.h"#include#includeclassEventHandler{public:intNum;std::functionOnEvent;EventHandler(intinNum){Num=inNum;}EventHandler(constEventHandler

C++ 原子 : would function call act as memory barrier?

我正在阅读这篇文章MemoryOrderingatCompileTime从中说:Infact,themajorityoffunctioncallsactascompilerbarriers,whethertheycontaintheirowncompilerbarrierornot.Thisexcludesinlinefunctions,functionsdeclaredwiththepureattribute,andcaseswherelink-timecodegenerationisused.Otherthanthosecases,acalltoanexternalfunction

c++ - 具有未触及的非 constexpr 参数 : Who is correct, clang 或 gcc 的 constexpr?

我有4个测试用例,我相信它们都是有效的:constexprintf(intconst&/*unused*/){return1;}voidg(intconst&p){constexprinta=f(p);//clangerror,gccvalidintv=0;constexprintb=f(v);//clangvalid,gccvalidintconst&r=v;constexprintc=f(r);//clangerror,gccerrorintn=p;constexprintd=f(n);//clangvalid,gccvalid}intmain(){intp=0;g(p);}Cla

c++ - 为什么 std::scan_is 在 vi​​sual studio 编译器中发出运行时错误?

示例here在VisualStudio2013中发出内存访问冲突的运行时错误。#include#include#includeintmain(){auto&f=std::use_facet>(std::locale(""));//skipuntilthefirstletterchars1[]="\t\t\nTest";constchar*p1=f.scan_is(std::ctype_base::alpha,std::begin(s1),std::end(s1));std::cout这是为什么呢?编译器的错误实现? 最佳答案 aut