草庐IT

static-assert

全部标签

c++ - Boost assert.hpp 文件中的 P::************ 是什么意思?

在boost/mpl/assert.hpp,我看到了这样的东西:templatestructeval_assert{typedeftypenameextract_assert_pred::typeP;typedeftypenameP::typep_type;typedeftypename::boost::mpl::if_c),failed************P::************>::typetype;};如果第一个************可以视为struct的指针失败,则P::************对我来说真的没有任何意义。这是标准的C++吗?

c++ - 弃用 static 关键字...不再?

在C++中,可以在翻译单元中使用static关键字来影响符号(变量或函数声明)的可见性。在n3092中,这已被弃用:AnnexD.2[depr.static]Theuseofthestatickeywordisdeprecatedwhendeclaringobjectsinnamespacescope(see3.3.6).在n3225中,这已被删除。onlyarticleIcouldfind有点不正式。它确实强调了,为了与C的兼容性(以及将C程序编译为C++的能力),弃用是令人讨厌的。但是,将C程序直接编译为C++可能已经是一种令人沮丧的体验,因此我不确定是否值得考虑。有谁知道为什么改

c++ - static_assert 有什么作用,你会用它做什么?

你能举一个例子,static_assert(...)('C++11')可以优雅地解决手头的问题吗?我熟悉运行时assert(...)。我什么时候应该更喜欢static_assert(...)而不是常规的assert(...)?另外,在boost中有一个叫做BOOST_STATIC_ASSERT的东西,和static_assert(...)一样吗? 最佳答案 静态断言用于在编译时进行断言。当静态断言失败时,程序根本无法编译。这在不同的情况下很有用,例如,如果您通过代码实现某些功能,该代码严重依赖于恰好具有32位的unsignedint

iphone - Objective-C 中的 NS_BLOCK_ASSERTIONS

我在iPhone应用程序中使用NSAssert()调用,我对Apple文档的理解是,如果定义了NS_BLOCK_ASSERTIONS,则断言不会编译到代码中。要关闭断言,我在头文件中声明:#defineNS_BLOCK_ASSERTIONS但是,断言代码似乎仍在运行。这里有什么我遗漏的吗?谢谢约翰 最佳答案 如果您基于标准模板之一创建了Xcode项目,则Cocoaheader(包括NSException.h,其中包含NSAssert宏)将在项目中的任何其他文件之前进行预处理。一个#defineNS_BLOCK_ASSERTIONS因

objective-c - 将未知行数添加到 'Static Cells' UITableView

我在InterfaceBuilder中创建了一个静态表,其中包含6个部分,所有部分的行数都不同。我现在想添加具有不同行数的第7部分。首先,一旦我取消注释由Xcode插入的标准表委托(delegate)方法,我就会在self.tableView.tableHeaderView=containerView;我在表格中添加了标题。更重要的是,下面的代码让我崩溃了-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{return7;}-(NSInteger)tableView:(UITableView*)tableVie

objective-c - 定义缓存变量时在objective-c中使用static关键字

我正在查看以下苹果示例源代码:/*Cachetheformatter.Normallyyouwoulduseoneofthedateformatterstyles(suchasNSDateFormatterShortStyle),butherewewantaspecificformatthatexcludesseconds.*/staticNSDateFormatter*dateFormatter=nil;if(dateFormatter==nil){dateFormatter=[[NSDateFormatteralloc]init];[dateFormattersetDateForm

c++ - Clang 和 GCC vs MSVC 和 ICC : Is a static_assert in the copy/move constructor required to work, 如果复制/移动省略也可以应用?

我的模板结构的移动构造函数中有一个static_assert。编译器是否需要考虑这个static_assert,即使复制省略是可能的?这是精简的场景:#includetemplatestructX{X(X&&){static_assert(std::is_same::value,"IntentionalFailure");}};autoimpl()->X;autotest()->decltype(impl()){returnimpl();}intmain(){test();}GCC和Clang同意评估static_assert并且编译失败。另一方面,MSCV和ICC可以很好地编译代码。

c++ - Clang 和 GCC vs MSVC 和 ICC : Is a static_assert in the copy/move constructor required to work, 如果复制/移动省略也可以应用?

我的模板结构的移动构造函数中有一个static_assert。编译器是否需要考虑这个static_assert,即使复制省略是可能的?这是精简的场景:#includetemplatestructX{X(X&&){static_assert(std::is_same::value,"IntentionalFailure");}};autoimpl()->X;autotest()->decltype(impl()){returnimpl();}intmain(){test();}GCC和Clang同意评估static_assert并且编译失败。另一方面,MSCV和ICC可以很好地编译代码。

php - PHP 中的 self::$bar 和 static::$bar 有什么区别?

下面例子中使用self和static有什么区别?classFoo{protectedstatic$bar=1234;publicstaticfunctioninstance(){echoself::$bar;echo"\n";echostatic::$bar;}}Foo::instance();产生12341234 最佳答案 当您使用self来指代类成员时,您指的是在其中使用关键字的类。在这种情况下,您的Foo类定义了一个名为$bar的protected静态属性。当您在Foo类中使用self来引用该属性时,您引用的是同一个类。因此,

PHP 5 : const vs static

在PHP5中,使用const和static有什么区别?什么时候合适?public、protected和private扮演什么角色-如果有的话? 最佳答案 在类的上下文中,静态变量位于类范围(而不是对象)范围内,但与const不同的是,它们的值可以更改。classClassName{static$my_var=10;/*defaultstopublicunlessotherwisespecified*/constMY_CONST=5;}echoClassName::$my_var;//returns10echoClassName::M