From b8d5d4c2bd1e8b9637782b36b8ccbafd2785070e Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 3 Jan 2017 10:03:28 +0100 Subject: Fix template condition for Vector.insertBack --- source/tanya/container/vector.d | 8 +++---- source/tanya/enums.d | 49 ----------------------------------------- source/tanya/meta/gen.d | 49 +++++++++++++++++++++++++++++++++++++++++ source/tanya/meta/package.d | 15 +++++++++++++ 4 files changed, 67 insertions(+), 54 deletions(-) delete mode 100644 source/tanya/enums.d create mode 100644 source/tanya/meta/gen.d create mode 100644 source/tanya/meta/package.d diff --git a/source/tanya/container/vector.d b/source/tanya/container/vector.d index ac26d43..0e67b54 100644 --- a/source/tanya/container/vector.d +++ b/source/tanya/container/vector.d @@ -15,8 +15,9 @@ import core.exception; import std.algorithm.comparison; import std.conv; import std.range.primitives; +import std.meta; import std.traits; -public import tanya.enums : IL; +public import tanya.meta.gen : IL; import tanya.memory; version (unittest) @@ -631,9 +632,6 @@ struct Vector(T) return toRemove; } - /// Ditto. - alias remove = removeBack; - /// unittest { @@ -655,7 +653,7 @@ struct Vector(T) * Returns: The number of elements inserted. */ size_t insertBack(R...)(auto ref R el) @trusted - if (isImplicitlyConvertible!(R[0], T)) + if (allSatisfy!(ApplyRight!(isImplicitlyConvertible, T), R)) { reserve(length_ + el.length); if (capacity_ <= length_) diff --git a/source/tanya/enums.d b/source/tanya/enums.d deleted file mode 100644 index 8fdbf8d..0000000 --- a/source/tanya/enums.d +++ /dev/null @@ -1,49 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Generic enum templates. - * - * Copyright: Eugene Wissner 2016. - * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, - * Mozilla Public License, v. 2.0). - * Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) - */ -module tanya.enums; - -import std.traits; - -/** - * Initializer list. - * - * Generates a static array with elements from $(D_PARAM args). All elements - * should have the same type. It can be used in constructors which accept a - * list of the elements of the same type in the situations where variadic - * functions and templates can't be used. - * - * Params: - * Args = Argument type. - * args = Arguments. - */ -enum IL(Args...)(Args args) - if (Args.length > 0) -{ - alias BaseType = typeof(args[0]); - - BaseType[args.length] result; - - foreach (i, a; args) - { - static assert(isImplicitlyConvertible!(typeof(a), BaseType)); - result[i] = a; - } - return result; -} - -/// -unittest -{ - static assert(IL(1, 5, 8).length == 3); - static assert(IL(1, 5, 8).sizeof == 3 * int.sizeof); -} diff --git a/source/tanya/meta/gen.d b/source/tanya/meta/gen.d new file mode 100644 index 0000000..a87a90b --- /dev/null +++ b/source/tanya/meta/gen.d @@ -0,0 +1,49 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Templates that generate values. + * + * Copyright: Eugene Wissner 2016. + * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, + * Mozilla Public License, v. 2.0). + * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) + */ +module tanya.meta.gen; + +import std.traits; + +/** + * Initializer list. + * + * Generates a static array with elements from $(D_PARAM args). All elements + * should have the same type. It can be used in constructors which accept a + * list of the elements of the same type in the situations where variadic + * functions and templates can't be used. + * + * Params: + * Args = Argument type. + * args = Arguments. + */ +enum IL(Args...)(Args args) + if (Args.length > 0) +{ + alias BaseType = typeof(args[0]); + + BaseType[args.length] result; + + foreach (i, a; args) + { + static assert(isImplicitlyConvertible!(typeof(a), BaseType)); + result[i] = a; + } + return result; +} + +/// +unittest +{ + static assert(IL(1, 5, 8).length == 3); + static assert(IL(1, 5, 8).sizeof == 3 * int.sizeof); +} diff --git a/source/tanya/meta/package.d b/source/tanya/meta/package.d new file mode 100644 index 0000000..c511220 --- /dev/null +++ b/source/tanya/meta/package.d @@ -0,0 +1,15 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Metaprogramming. + * + * Copyright: Eugene Wissner 2016. + * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, + * Mozilla Public License, v. 2.0). + * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) + */ +module tanya.meta; + +public import tanya.meta.gen; -- cgit v1.2.3