mixin template TStructHelpers(alias fieldMetaData = cast(TFieldMeta[])null) if (
is(typeof(fieldMetaData) : TFieldMeta[])
) {
- import std.algorithm : canFind;
+ import std.algorithm : any;
import thrift.codegen.base;
import thrift.internal.codegen : isNullable, MemberType, mergeFieldMeta,
FieldNames;
return true;
}
- static if (canFind!`!a.defaultValue.empty`(mergeFieldMeta!(This, fieldMetaData))) {
+ static if (any!`!a.defaultValue.empty`(mergeFieldMeta!(This, fieldMetaData))) {
static if (is(This _ == class)) {
this() {
mixin(thriftFieldInitCode!(mergeFieldMeta!(This, fieldMetaData))("this"));
return code;
}
-version (unittest) {
+unittest {
// Cannot make this nested in the unittest block due to a »no size yet for
// forward reference« error.
- struct Foo {
+ static struct Foo {
string a;
int b;
int c;
TFieldMeta("c", 3, TReq.REQUIRED, "4")
]);
}
-}
-unittest {
+
auto f = Foo();
f.set!"b"(12345);
module thrift.internal.codegen;
+import std.algorithm : canFind;
import std.traits : InterfacesTuple, isSomeFunction, isSomeString;
import std.typetuple : staticIndexOf, staticMap, NoDuplicates, TypeTuple;
import thrift.codegen.base;
template FieldNames(T, alias fieldMetaData = cast(TFieldMeta[])null) {
alias StaticFilter!(
All!(
+ doesNotReadMembers,
PApply!(isValueMember, T),
PApply!(notIgnored, T, PApplySkip, fieldMetaData)
),
) FieldNames;
}
+/*
+ * true if the passed member name is not a method generated by the
+ * TStructHelpers template that in its implementations queries the struct
+ * members.
+ *
+ * Kludge used internally to break a cycle caused a DMD forward reference
+ * regression, see THRIFT-2130.
+ */
+enum doesNotReadMembers(string name) = !["opEquals", "thriftOpEqualsImpl",
+ "toString", "thriftToStringImpl"].canFind(name);
+
template derivedMembers(T) {
alias TypeTuple!(__traits(derivedMembers, T)) derivedMembers;
}
import std.traits : isImplicitlyConvertible, ParameterTypeTuple;
import std.range : ElementType, isInputRange;
+struct Void {}
+
/**
* A quickly hacked together hash set implementation backed by built-in
* associative arrays to have something to compile Thrift's set<> to until
///
void insert(Stuff)(Stuff stuff) if (isImplicitlyConvertible!(Stuff, E)) {
- aa_[*(cast(immutable(E)*)&stuff)] = [];
+ aa_[*(cast(immutable(E)*)&stuff)] = Void.init;
}
///
isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, E)
) {
foreach (e; stuff) {
- aa_[*(cast(immutable(E)*)&e)] = [];
+ aa_[*(cast(immutable(E)*)&e)] = Void.init;
}
}
}
private:
- alias void[0] Void;
Void[immutable(E)] aa_;
}