阅读http://en.cppreference.com/w/cpp/language/for我发现,循环的条件部分for
可以是表达式,上下文可转换为bool
或单变量声明,带有强制括号或相等的初始值设定项( 6.4/1中的语法规范):
条件:
- 表达
- type-specifier-seq declarator = assignment-expression
但我从来没有在源代码中看到过使用后者.
什么是盈利的(为了简洁,表现力,可读性感)利用变量声明的条件的一部分for
循环语句?
for (int i = 0; bool b = i < 5; ++i) {
// `b` is always convertible to `true` until the end of its scope
} // scope of `i` and `b` ends here
Run Code Online (Sandbox Code Playgroud)
如果没有影响转换结果的副作用,则在条件中声明的变量只能true
在整个生命周期(范围)内转换bool
.
我只能想象几个用例:
operator bool
.某种改变循环变量的cv-ref-qualifiers:
for (int i = 5; int …
Run Code Online (Sandbox Code Playgroud)如何初始化数据以及向数组添加值
(
[0] => Array
(
[name] => First element
[foo] => bar
)
[1] => Array
(
[name] => Second element
[foo] => bar2
)
)
Run Code Online (Sandbox Code Playgroud) 我的代码中遇到内存错误.我的解析器可以总结如下:
# coding=utf-8
#! /usr/bin/env python
import sys
import json
from collections import defaultdict
class MyParserIter(object):
def _parse_line(self, line):
for couple in line.split(","):
key, value = couple.split(':')[0], couple.split(':')[1]
self.__hash[key].append(value)
def __init__(self, line):
# not the real parsing just a example to parse each
# line to a dict-like obj
self.__hash = defaultdict(list)
self._parse_line(line)
def __iter__(self):
return iter(self.__hash.values())
def to_dict(self):
return self.__hash
def __getitem__(self, item):
return self.__hash[item]
def free(self, item):
self.__hash[item] = None
def free_all(self):
for k in self.__hash:
self.free(k)
def …
Run Code Online (Sandbox Code Playgroud) 我正在根据OAuth 2.0构建授权服务器.
还有一个使用我的授权服务器的第三方Web应用程序(客户端).它是一个常规的Web应用程序,用户可能会使用此应用程序建立多个活动会话(例如,办公室和家庭计算机,或同一台计算机上的几个Web浏览器).
我的授权服务器为客户端发出一次访问令牌#1(带或不带刷新令牌,这在此处并不重要).当用户与客户端启动新会话时,授权服务器是否应该为客户端应用程序提供该新会话的相同访问令牌#1,还是应该发出新的#2令牌?
我的想法:
从安全的角度来看,新令牌可能听起来更好,但如果用户想要管理他的授权,他将看到每个客户端会话的单独条目,这可能是混乱的.
例如,GitHub为以前授权的客户端返回相同的令牌,在我的GitHub帐户的"应用程序"页面上,我看到每个应用程序只有一个条目,无论我启动了多少个会话,这很方便.
但是,这种方法意味着我必须以可逆方式(纯文本或使用某些已知密钥加密)在授权或资源服务器中存储访问令牌,而不是使用不可逆的散列(就像您通常使用密码,存储salt和密码哈希)来自bcrypt,pbkdf2或类似的东西).
我正在使用R(ggplot2)绘制图形。在那里,我需要手动调整限制。
当我使用以下代码时,我得到警告:“'y'的比例已经存在。为'y'添加另一个比例,它将替换现有的比例。”
plot = ggplot(Light.d220, aes(x=V1, y=V2)) +
geom_raster(aes(fill=V3), interpolate=TRUE, hjust = 0, vjust = 0) +
scale_fill_gradient(low = "red",high = "green") +
guides(fill = guide_colorbar(barwidth = 1, barheight = 10, title="Lux")) +
labs(x = "X", y = "Y", title= "Illumination at 2,2 m [Lux]") +
geom_text(aes(label=V3),size=5) +
xlim(-0.6,4.4) +
ylim(0,1.02) +
scale_y_reverse()
Run Code Online (Sandbox Code Playgroud)
我知道由于“ ylim”而收到此错误,但我不知道如何更正此错误。
如果您能告诉我如何解决这个问题,那就太好了。
非常感谢你 :-)
我正在尝试使用URLConnection下载pdf文件.这是我设置连接对象的方法.
URL serverUrl = new URL(url);
urlConnection = (HttpURLConnection) serverUrl.openConnection();
urlConnection.setDoInput(true);
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Content-Type", "application/pdf");
urlConnection.setRequestProperty("ENCTYPE", "multipart/form-data");
String contentLength = urlConnection.getHeaderField("Content-Length");
Run Code Online (Sandbox Code Playgroud)
我从连接对象获得了输入流.
bufferedInputStream = new BufferedInputStream(urlConnection.getInputStream());
Run Code Online (Sandbox Code Playgroud)
并输出流来写入文件内容.
File dir = new File(context.getFilesDir(), mFolder);
if(!dir.exists()) dir.mkdir();
final File f = new File(dir, String.valueOf(documentName));
f.createNewFile();
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(f, true)); //true for appendMode
Run Code Online (Sandbox Code Playgroud)
创建BlockingQueue,以便执行读写操作的线程可以访问队列.
final BlockingQueue<ByteArrayWrapper> blockingQueue = new ArrayBlockingQueue<ByteArrayWrapper>(MAX_VALUE,true);
final byte[] dataBuffer = new byte[MAX_VALUE];
Run Code Online (Sandbox Code Playgroud)
现在创建了从InputStream读取数据的线程.
Thread readerThread = new Thread(new Runnable() {
@Override
public void run() {
try …
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我对openejb-core
范围有依赖性provided
.但它具有传递依赖性,slf4j
其范围是compile
(见截图).所有其他传递依赖项都按预期提供.
问题:是错误还是我错过了什么?
嗨,我是typescritpt的新手,我来自C#和Javascript背景.我正在尝试创建一种方法,允许我创建类似于我们在C#中可以做的类模型.这是我尝试过的:
export class DonutChartModel {
dimension: number;
innerRadius: number;
backgroundClass: string;
backgroundOpacity: number;
}
Run Code Online (Sandbox Code Playgroud)
我希望这能生成一个公开声明属性的javascript模型,但这些模型只生成一个没有声明属性的函数DonutChartModel.
在查看文档后,我注意到为了公开属性,我必须添加一个构造函数,从那里初始化属性.虽然这可能有效,但是对于每个模型可能有20个或更多特性的情况,初始化在我看来可能看起来比较安全,并且还会降低可读性.
我希望有一种方法可以做这样的事情而不传递构造函数params:
var model = new DonutChartModel();
model.dimension = 5
model.innerRadius = 20
....
Run Code Online (Sandbox Code Playgroud)
那么打字稿中是否有任何选项可以做到这一点?
我发现一些帖子描述了何时使用Auto布局和何时使用Size类之间的区别.
但我仍然无法理解这两者之间的区别.
如果任何人可以暗示差异或分享一个良好的链接.
提前致谢!
我在获取自定义字体的名称时遇到问题.如果需要选中选项,我在我的项目中添加了字体.我将字体名称添加到应用程序提供的info.plist标记字体中.我将字体添加到Copy Bundle Resources.
字体显示在自定义选项卡下的故事板中.但是当我试图用代码找到这个字体的名称时,它不起作用.真奇怪,因为这通常有效.这可能是什么原因?
故事板图片的字体:
用于以编程方式查找名称的代码:
viewDidLoad(){
// there is no PTSans family in the debugger.
for family: String in UIFont.familyNames()
{
print("\(family)")
for names: String in UIFont.fontNamesForFamilyName(family)
{
print("== \(names)")
}
}
}
Run Code Online (Sandbox Code Playgroud) ios ×2
java ×2
android ×1
autolayout ×1
c++ ×1
font-family ×1
fonts ×1
for-loop ×1
ggplot2 ×1
json ×1
maven ×1
maven-3 ×1
oauth ×1
oauth-2.0 ×1
optimization ×1
performance ×1
pom.xml ×1
python ×1
r ×1
security ×1
size-classes ×1
swift ×1
typescript ×1
xcode ×1
xcode6 ×1