1 /******************************************************************************* 2 3 Traits for arrays and array-like types. 4 5 Note: utils that operate on array types but evaluate to another type (and 6 not some compile-time value) reside in `ocean.meta.types.Arrays`, not in 7 this module. 8 9 Copyright: 10 Copyright (C) 2017 dunnhumby Germany GmbH. All rights reserved. 11 12 License: 13 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 14 Alternatively, this file may be distributed under the terms of the Tango 15 3-Clause BSD License (see LICENSE_BSD.txt for details). 16 17 *******************************************************************************/ 18 19 module ocean.meta.traits.Arrays; 20 21 import ocean.meta.traits.Basic; 22 import ocean.meta.types.Arrays; 23 import ocean.meta.types.Qualifiers; 24 25 /******************************************************************************* 26 27 Params: 28 T = any type 29 30 Returns: 31 `true` if T represents UTF-8 string type 32 33 *******************************************************************************/ 34 35 template isUTF8StringType ( T ) 36 { 37 static immutable isUTF8StringType = 38 isBasicArrayType!(T) && is(Unqual!(ElementTypeOf!(T)) == char); 39 } 40 41 /// 42 unittest 43 { 44 static assert (isUTF8StringType!(char[1])); 45 static assert (isUTF8StringType!(char[])); 46 static assert (isUTF8StringType!(immutable(char)[])); 47 static assert (!isUTF8StringType!(wchar[])); 48 } 49 50 /******************************************************************************* 51 52 Params: 53 T = any type 54 55 Returns: 56 Depth of array nesting (1 for plain array) if T is an array, 0 otherwise 57 58 *******************************************************************************/ 59 60 template rankOfArray ( T ) 61 { 62 static if (is(T S : S[])) 63 enum rankOfArray = 1 + rankOfArray!S; 64 else 65 enum rankOfArray = 0; 66 } 67 68 /// 69 unittest 70 { 71 static assert (rankOfArray!(real[][]) == 2); 72 static assert (rankOfArray!(real[2][]) == 2); 73 }