有可能进行编译时Type -> Enum Series映射吗?
举例说明:
比方说,我有一些Type枚举值:
typedef int Type;
enum Enumerated { Enum1, Enum2, Enum3, Enum4 };
Run Code Online (Sandbox Code Playgroud)
现在我以某种方式陈述以下内容:"让我们关联Enum1并Enum4
与类型Type (不知道如何实现这一点).
现在我希望能够检查以下内容(最好在编译时使用mpl完成):
如果某些任意类型和枚举实际上彼此映射:
template <typename ArbitraryType, Enumerated E>
struct check_at_compile_time {
// Somehow tricky evaluate this
static const bool value;
};
Run Code Online (Sandbox Code Playgroud)
以便结果如下:
check_at_compile_time<Type, Enum1>::value evaluates to TRUE
check_at_compile_time<Type, Enum2>::value evaluates to FALSE
check_at_compile_time<Type, Enum4>::value evaluates to TRUE
check_at_compile_time<int, Enum3>::value evaluates to FALSE
Run Code Online (Sandbox Code Playgroud)
如果有人知道实现这个的好方法,请帮助我.也许使用的东西boost::mpl,我不确定.
谢谢.
我没有找到办法 - 仅编辑现有字段的翻译.
如果没有办法实现这一点 - 应该如何做到(不知何故自动,因为现在我正在手动添加
<message>
<source>x</source>
<translation>xx</translation>
</message>
Run Code Online (Sandbox Code Playgroud)
阻止我的.ts文件,我认为这不是正确的方法.
有人可能会指出为什么以下代码在第一种情况下失败:
情况1
// In a constructor
this.gallery = new Gallery();
addChild(this.gallery);
this.gallery.addEventListener(GalleryEvent.WHATEVER, function(event:*) {
// When this callback fires, there is a fail:
// because there is no 'this.gallery'.
this.gallery.someAction();
});
Run Code Online (Sandbox Code Playgroud)
案例2
this.gallery.addEventListener(GalleryEvent.WHATEVER, function(event:*) {
// This works fine
gallery.someAction();
})
Run Code Online (Sandbox Code Playgroud)
this在这种情况下是否有关于使用的规则?
有人可以指出重载的想法operator==来执行深度对象比较(而不是参考比较).
来自MSDN:
默认情况下,operator ==通过确定两个引用是否指示同一对象来测试引用相等性.因此,引用类型不必实现operator ==以获得此功能.当一个类型是不可变的,也就是说,实例中包含的数据不能改变时,重载operator ==来比较值的相等而不是引用相等可能是有用的,因为作为不可变对象,它们可以被认为是相同的因为它们具有相同的价值.在非不可变类型中覆盖operator ==不是一个好主意.
什么时候才真正受益?
并且,如果每个对象都有方法Equals,这使得值比较成为可能,为什么有人会使用语句执行值 (而不是引用)比较x == y?
我想我不明白,因为这对我来说很奇怪.
我正在使用NHibernate-driven存储库,Fluent映射并尝试使用Linq to NHibernate.
但对于像这样的一些简单查询
Retrieve<XValue>(x => (x.Timestamp.CompareTo(start) >= 0 &&
x.Timestamp.CompareTo(end) <= 0 ));
// 'Retrieve' here acts simply as 'session.Query<T>().Where(expression);'
Run Code Online (Sandbox Code Playgroud)
我得到以下结果:
System.NotSupportedException: Int32 CompareTo(System.DateTime)
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但CompareTo操作不会投射到数据库,输出也有点奇怪:
create table "QuotUnitDescriptor" (
Id integer,
PaperId INTEGER,
Timestamp DATETIME,
InPaperIdx INTEGER,
primary key (Id)
)
NHibernate: INSERT INTO "QuotUnitDescriptor" ......................
// Many INSERT's
NHibernate: select cast(count(*) as INTEGER) as col_0_0_
from "QuotUnitDescriptor" binaryunit0_
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么这个操作会调用一个select -> integer操作.
如何实现以下面向日期的查询? (使用Linq更好,但我认为标准也很好).
如果我有一个IDictionary<int, int>,是否有可能收到一个IEnumerable<int>,其中包含每个被KeyValuePair<int, int>拆解成(int, int)一个接一个插入的两个条目?
小例子:
Dictionary:
5 - 25
6 - 36
7 - 49
Wanted Enumerable:
5, 25, 6, 36, 7, 49
Run Code Online (Sandbox Code Playgroud)
另外,我希望在一个非常漂亮的声明中有这个,但我想不出一个合适的:)
更新:
是否LINQ允许插入每一个以上的元素.Select声明,共享的东西的想法:
xyz.Select(t => (t, null))
Run Code Online (Sandbox Code Playgroud)
使得所得Enumerable将同时包含t和null之后呢?
有人可以解释一下这怎么可能:
foreach (var pair in Expected.Zip(
Actual, (x, y) => new { Expected = x, Actual = y }))
{
// No match for a 'null' series.
if (pair.Actual == null) yield return 0;
var actualPaths = pair.Actual.Images.Select(x => x.Path).ToList();
}
Run Code Online (Sandbox Code Playgroud)
这段代码(in Microsoft Visual Studio 2008)在线停止var actualPaths = ...并表示pair.Actual等于null,因此提高了一个NullReferenceException.
这怎么可能呢?我错过了什么吗?
可以ICollection<T>.Count属性getter被视为原子(因此,threadsafe)?
谢谢.
有没有办法通过代理使以下功能工作?
public T[] ReadStream(System.IO.TextReader reader);
我希望能够代理reader实例,以便它可以在读取尝试时从Web下载文件并将其缓存到某处.
或者为此可能有默认值?
有可能以某种方式实现以下方案:
public interface ISomething
{
void Go(ISpecific specific);
void Go(Object o);
}
Run Code Online (Sandbox Code Playgroud)
让每个Go(ISpecific)拨打第一个重载会被调用,与其他任何可能的对象调用的类将回退到的Go(Object)实施?
c# ×7
c++ ×2
linq ×2
.net ×1
actionscript ×1
arguments ×1
boost-mpl ×1
collections ×1
comparison ×1
download ×1
enums ×1
equality ×1
fallback ×1
flash ×1
merge ×1
nhibernate ×1
null ×1
overloading ×1
properties ×1
proxy ×1
qt ×1
templates ×1
textreader ×1
this ×1
translation ×1
types ×1