在C++中定义函数模板或类模板时,可以这样写:
template <class T> ...
Run Code Online (Sandbox Code Playgroud)
或者可以这样写:
template <typename T> ...
Run Code Online (Sandbox Code Playgroud)
是否有充分理由偏好一个而不是另一个?
我接受了最受欢迎(也很有趣)的答案,但真正的答案似乎是"不,没有理由偏爱另一个."
typename.class.但是,请注意,在模板模板参数的情况下,需要使用class而不是typename.请参阅下面的user1428839的答案.(但这个特殊情况不是偏好问题,而是语言的要求.)(这也会改变typename)
服务器端的代码在连接打开后立即发送消息(它向客户端发送初始配置/问候语).
以下代码在客户端:
var sock = new WebSocket(url);
sock.addEventListener('error', processError);
sock.addEventListener('close', finish);
sock.addEventListener('message', processMessage);
Run Code Online (Sandbox Code Playgroud)
我担心从服务器丢失这个第一个配置/问候相关的消息.理论上没有什么能阻止在 message设置事件处理程序之前接收它.
另一方面,实际上我从来没有想过.并且AFAIK JavaScript WebSocket API没有针对这个理论问题的对策:WebSocket 构造函数既不允许message设置事件处理程序,也不允许在挂起状态下创建WebSocket.
所以:
?
PS:这样简单但理论上的问题更适合Stack Overflow或Programmers @ Stack Exchange吗?
有没有办法在powershell中判断指定文件是否包含指定的字节数组(在任意位置)?
\n\n就像是:
\n\nfgrep --binary-files=binary "$data" "$filepath"\nRun Code Online (Sandbox Code Playgroud)\n\n当然,我可以写一个简单的实现:
\n\nfunction posOfArrayWithinArray {\n param ([byte[]] $arrayA, [byte[]]$arrayB)\n if ($arrayB.Length -ge $arrayA.Length) {\n foreach ($pos in 0..($arrayB.Length - $arrayA.Length)) {\n if ([System.Linq.Enumerable]::SequenceEqual(\n $arrayA,\n [System.Linq.Enumerable]::Skip($arrayB, $pos).Take($arrayA.Length)\n )) {return $pos}\n }\n }\n -1\n}\n\nfunction posOfArrayWithinFile {\n param ([byte[]] $array, [string]$filepath)\n posOfArrayWithinArray $array (Get-Content $filepath -Raw -AsByteStream)\n}\n\n// They return position or -1, but simple $false/$true are also enough for me.\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\x94 但速度非常慢。
\n在阅读Windows PowerShell 博客上这篇有用的文章后,我意识到我可以“移动”数组的第一部分,但不知道如何在 PowerShell 中“取消移动”或将元素推送到数组的前面。
我正在创建一个哈希对象数组,最后读取的项目首先推送到数组上。我想知道是否有更好的方法来实现这一点。
## Create a list of files for this collection, pushing item on top of all other items
if ($csvfiles[$collname]) {
$csvfiles[$collname] = @{ repdate = $date; fileobj = $csv }, $csvfiles[$collname] | %{$_}
}
else {
$csvfiles[$collname] = @{ repdate = $date; fileobj = $csv }
}
Run Code Online (Sandbox Code Playgroud)
有几点需要注意:
想法?
PS:空哈希元素产生 NULL 值的原因是 $null 在 PowerShell 中被视为标量。有关详细信息,请参阅https://connect.microsoft.com/PowerShell/feedback/details/281908/foreach-should-not-execute-the-loop-body-for-a-scalar-value-of-null。
回答:
看起来最好的解决方案是在必要时预先创建空数组,而不是围绕 $null 问题编写代码。下面是使用 .NET ArrayList …
我在Heroku上运行使用postgres的应用程序.
我的所有SQL语句都在我的日志中出现; 我想把它关掉.
它们看起来像这样:
Dec 03 05:41:36 ti-core app/postgres: [1566-2] #011FROM alias
Dec 03 05:41:36 ti-core app/postgres: [1566-3] #011WHERE alias.nid = E'10.5334/sta.at' AND alias.namespace = E'doi'
Dec 03 05:41:36 ti-core app/postgres: [1566-4] #011 LIMIT 1
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚我在哪里设置了这个级别的heroku postgres调试以及在哪里将其降低了一个档次.谢谢!
为什么ByteArrayOutputStream。close是用throws IOException? 首先,事实上它不能扔任何东西,因为它的身体是空的。其次,在法律上它不能抛出任何东西,因为它的文档说“关闭 ByteArrayOutputStream 没有任何效果”。
这不是(不重要,但仍然)有点错误吗?
是的,我知道它的超类OutputStream实现了Closable,其close方法允许 throw IOException。但是没有人禁止使用没有抛出规范的方法覆盖它(in ByteArrayOutputStream)close。(即使在某些古老的 Java 版本中禁止用更少抛出的方法覆盖更多抛出的方法,现在更改ByteArrayOutputStream.close定义不会是不兼容的更改。)
以下内容composer.json:
{
"type": "project",
"minimum-stability": "dev",
"require": {
"jasny/bootstrap": ">=3.1.3",
"2amigos/yii2-file-input-widget": "*"
}
}
Run Code Online (Sandbox Code Playgroud)
导致以下输出composer update:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- 2amigos/yii2-file-input-widget 0.1.2 requires jasny/bootstrap v3.1.0 -> satisfiable by jasny/bootstrap[v3.1.0] but these conflict with your requirements or minimum-stability.
- 2amigos/yii2-file-input-widget 0.1.1 requires jasny/bootstrap v3.1.0 -> satisfiable by jasny/bootstrap[v3.1.0] but these conflict with your requirements or minimum-stability. …Run Code Online (Sandbox Code Playgroud) 从Scala之旅的统一类型文章中的这个方案我认为并且是完全等价的.AnyRefObject
但是,在Eclipse中检查声明时,我发现了一些有趣的东西:
object ClassTag {
…
val Object : ClassTag[java.lang.Object] = Manifest.Object
…
val AnyRef : ClassTag[scala.AnyRef] = Manifest.AnyRef
…
}
object TypeTag {
…
val AnyRef: TypeTag[scala.AnyRef] = new PredefTypeTag[scala.AnyRef] (AnyRefTpe, _.TypeTag.AnyRef)
val Object: TypeTag[java.lang.Object] = new PredefTypeTag[java.lang.Object] (ObjectTpe, _.TypeTag.Object)
…
}
Run Code Online (Sandbox Code Playgroud)
一些实验:
import scala.reflect.ClassTag
import scala.reflect.runtime.universe.TypeTag
println(ClassTag.AnyRef == ClassTag.Object) //true
def getClassTag[V](v: V)(implicit tag: ClassTag[V]) = tag
println(getClassTag[AnyRef](null)) //Object
println(getClassTag[Object](null)) //Object
println(getClassTag(null.asInstanceOf[AnyRef])) //Object
println(getClassTag(null.asInstanceOf[Object])) //Object
println(getClassTag(new AnyRef())) //Object
println(getClassTag(new Object())) //Object
println …Run Code Online (Sandbox Code Playgroud) 假设我有一个模板:
template<typename T>
struct Foo {int f1, f2;};
Run Code Online (Sandbox Code Playgroud)
我想为它创建一个新的别名.
// This will not work, don't even try:
// using Foo = Bar;
// Instead do like this:
template<typename T>
using Bar = Foo<T>;
Run Code Online (Sandbox Code Playgroud)
哇.它似乎工作.首先.但是......如果我有这样的功能:
// Generic f:
template<template<typename> class Tpl>
void f() {std::cout<<"Generic f"<<std::endl;}
// Specialization of f for Foo:
template<> void f<Foo>() {std::cout<<"f<Foo>"<<std::endl;}
int main() {...; f<Bar>(); ...} //outputs "Generic f"
Run Code Online (Sandbox Code Playgroud)
似乎f <Foo>和f <Bar>是f的不同特化!
所以:
谢谢.
powershell ×2
templates ×2
alias ×1
arrays ×1
binaryfiles ×1
c++ ×1
c++11 ×1
composer-php ×1
grep ×1
heroku ×1
java ×1
javascript ×1
logging ×1
postgresql ×1
scala ×1
stream ×1
types ×1
using ×1
websocket ×1