Thread overview | |||||
---|---|---|---|---|---|
|
August 05, 2010 [Issue 4582] New: distinct field names constraint for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4582 Summary: distinct field names constraint for std.typecons.Tuple Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: patch Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2010-08-04 17:21:25 PDT --- It's better to put guards as template constraints at the std.typecons.Tuple, so erroneous Tuple template instantiations fail at the instantiation point, giving a more useful error message in the user code instead giving an error inside the std.typecons module (this is one of the main purposes of template constraints). This code guards against duplicated field names: private template Iota(int stop) { // this is useful in general static if (stop <= 0) alias TypeTuple!() Iota; else alias TypeTuple!(Iota!(stop-1), stop-1) Iota; } private bool distinctFieldNames(T...)() { enum int tlen = T.length; // can't move this below, probably DMD bug foreach (i1; Iota!(tlen)) static if (is(typeof(T[i1]) : string)) foreach (i2; Iota!(tlen)) static if (i1 != i2 && is(typeof(T[i2]) : string)) if (T[i1] == T[i2]) return false; return true; } // ............... struct Tuple(T...) if (distinctFieldNames!(T)()) { -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 07, 2010 [Issue 4582] distinct field names constraint for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4582 Andrei Alexandrescu <andrei@metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |andrei@metalanguage.com AssignedTo|nobody@puremagic.com |andrei@metalanguage.com --- Comment #1 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-10-07 08:02:31 PDT --- Excellent. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 07, 2010 [Issue 4582] distinct field names constraint for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=4582 --- Comment #2 from bearophile_hugs@eml.cc 2010-10-07 13:25:43 PDT --- Thank you. But I think some tests/benchmarks may be done to make sure this extra test doesn't slow down too much the compilation of programs that define many tuple types. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation