diff options
| author | Eugen Wissner <belka@caraus.de> | 2019-03-17 10:56:44 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2019-03-17 10:56:44 +0100 |
| commit | 5ab99cf8873b130284336c52551ccede28f6cb2e (patch) | |
| tree | a8f0770dfd9410566eb6d941fbea78b1ce840a9a /meta | |
| parent | 85d7a2b9ca122301bc1ba9e6167f7533cbd1b2e4 (diff) | |
| download | tanya-5ab99cf8873b130284336c52551ccede28f6cb2e.tar.gz | |
Move memory functions into memory.lifecycle
- move
- moveEmplace
- forward
- emplace
- swap
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/dub.json | 9 | ||||
| -rw-r--r-- | meta/tanya/meta/metafunction.d (renamed from meta/source/tanya/meta/metafunction.d) | 4 | ||||
| -rw-r--r-- | meta/tanya/meta/package.d (renamed from meta/source/tanya/meta/package.d) | 4 | ||||
| -rw-r--r-- | meta/tanya/meta/trait.d (renamed from meta/source/tanya/meta/trait.d) | 56 | ||||
| -rw-r--r-- | meta/tanya/meta/transform.d (renamed from meta/source/tanya/meta/transform.d) | 4 |
5 files changed, 68 insertions, 9 deletions
diff --git a/meta/dub.json b/meta/dub.json index c8d2ba7..663d2fd 100644 --- a/meta/dub.json +++ b/meta/dub.json @@ -1,5 +1,12 @@ { "name": "meta", "description": "Template metaprogramming", - "targetType": "library" + "targetType": "library", + + "sourcePaths": [ + "." + ], + "importPaths": [ + "." + ] } diff --git a/meta/source/tanya/meta/metafunction.d b/meta/tanya/meta/metafunction.d index 6da6b47..a05b5cf 100644 --- a/meta/source/tanya/meta/metafunction.d +++ b/meta/tanya/meta/metafunction.d @@ -9,11 +9,11 @@ * It contains different algorithms for iterating, searching and modifying * template arguments. * - * Copyright: Eugene Wissner 2017-2018. + * Copyright: Eugene Wissner 2017-2019. * 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) - * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/meta/metafunction.d, + * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/meta/tanya/meta/metafunction.d, * tanya/meta/metafunction.d) */ module tanya.meta.metafunction; diff --git a/meta/source/tanya/meta/package.d b/meta/tanya/meta/package.d index d93e4fa..f06a166 100644 --- a/meta/source/tanya/meta/package.d +++ b/meta/tanya/meta/package.d @@ -9,11 +9,11 @@ * to transform from one type to another. It has also different algorithms for * iterating, searching and modifying template arguments. * - * Copyright: Eugene Wissner 2017-2018. + * Copyright: Eugene Wissner 2017-2019. * 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) - * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/meta/package.d, + * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/meta/tanya/meta/package.d, * tanya/meta/package.d) */ module tanya.meta; diff --git a/meta/source/tanya/meta/trait.d b/meta/tanya/meta/trait.d index 69b97b9..ebea9ce 100644 --- a/meta/source/tanya/meta/trait.d +++ b/meta/tanya/meta/trait.d @@ -8,11 +8,11 @@ * Templates in this module are used to obtain type information at compile * time. * - * Copyright: Eugene Wissner 2017-2018. + * Copyright: Eugene Wissner 2017-2019. * 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) - * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/meta/trait.d, + * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/meta/tanya/meta/trait.d, * tanya/meta/trait.d) */ module tanya.meta.trait; @@ -2693,6 +2693,58 @@ if (is(T == class)) } /** + * Returns the size in bytes of the state that needs to be allocated to hold an + * object of type $(D_PARAM T). + * + * There is a difference between the `.sizeof`-property and + * $(D_PSYMBOL stateSize) if $(D_PARAM T) is a class or an interface. + * `T.sizeof` is constant on the given architecture then and is the same as + * `size_t.sizeof` and `ptrdiff_t.sizeof`. This is because classes and + * interfaces are reference types and `.sizeof` returns the size of the + * reference which is the same as the size of a pointer. $(D_PSYMBOL stateSize) + * returns the size of the instance itself. + * + * The size of a dynamic array is `size_t.sizeof * 2` since a dynamic array + * stores its length and a data pointer. The size of the static arrays is + * calculated differently since they are value types. It is the array length + * multiplied by the element size. + * + * `stateSize!void` is `1` since $(D_KEYWORD void) is mostly used as a synonym + * for $(D_KEYWORD byte)/$(D_KEYWORD ubyte) in `void*`. + * + * Params: + * T = Object type. + * + * Returns: Size of an instance of type $(D_PARAM T). + */ +template stateSize(T) +{ + static if (isPolymorphicType!T) + { + enum size_t stateSize = __traits(classInstanceSize, T); + } + else + { + enum size_t stateSize = T.sizeof; + } +} + +/// +@nogc nothrow pure @safe unittest +{ + static assert(stateSize!int == 4); + static assert(stateSize!bool == 1); + static assert(stateSize!(int[]) == (size_t.sizeof * 2)); + static assert(stateSize!(short[3]) == 6); + + static struct Empty + { + } + static assert(stateSize!Empty == 1); + static assert(stateSize!void == 1); +} + +/** * Tests whether $(D_INLINECODE pred(T)) can be used as condition in an * $(D_KEYWORD if)-statement or a ternary operator. * diff --git a/meta/source/tanya/meta/transform.d b/meta/tanya/meta/transform.d index 5697e69..083e7ee 100644 --- a/meta/source/tanya/meta/transform.d +++ b/meta/tanya/meta/transform.d @@ -9,11 +9,11 @@ * types. They take some type as argument and return a different type after * perfoming the specified transformation. * - * Copyright: Eugene Wissner 2017-2018. + * Copyright: Eugene Wissner 2017-2019. * 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) - * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/meta/transform.d, + * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/meta/tanya/meta/transform.d, * tanya/meta/transform.d) */ module tanya.meta.transform; |
