1 /* 2 Copyright (c) 2011-2021 Timur Gafarov 3 4 Boost Software License - Version 1.0 - August 17th, 2003 5 6 Permission is hereby granted, free of charge, to any person or organization 7 obtaining a copy of the software and accompanying documentation covered by 8 this license (the "Software") to use, reproduce, display, distribute, 9 execute, and transmit the Software, and to prepare derivative works of the 10 Software, and to permit third-parties to whom the Software is furnished to 11 do so, all subject to the following: 12 13 The copyright notices in the Software and this entire statement, including 14 the above license grant, this restriction and the following disclaimer, 15 must be included in all copies of the Software, in whole or in part, and 16 all derivative works of the Software, unless such copies or derivative 17 works are solely in the form of machine-executable object code generated by 18 a source language processor. 19 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 23 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 24 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 DEALINGS IN THE SOFTWARE. 27 */ 28 29 /** 30 * Templates that construct tuples of numeric values 31 * 32 * Copyright: Timur Gafarov 2011-2021. 33 * License: $(LINK2 https://boost.org/LICENSE_1_0.txt, Boost License 1.0). 34 * Authors: Timur Gafarov 35 */ 36 module dlib.core.tuple; 37 38 /// Create a tuple 39 template Tuple(E...) 40 { 41 alias Tuple = E; 42 } 43 44 /// Yields a tuple of integer literals from 0 to stop 45 template RangeTuple(int stop) 46 { 47 static if (stop <= 0) 48 alias RangeTuple = Tuple!(); 49 else 50 alias RangeTuple = Tuple!(RangeTuple!(stop-1), stop-1); 51 } 52 53 /// Yields a tuple of integer literals from start to stop 54 template RangeTuple(int start, int stop) 55 { 56 static if (stop <= start) 57 alias RangeTuple = Tuple!(); 58 else 59 alias RangeTuple = Tuple!(RangeTuple!(start, stop-1), stop-1); 60 } 61 62 /// Yields a tuple of integer literals from start to stop with defined step 63 template RangeTuple(int start, int stop, int step) 64 { 65 static assert(step != 0, "RangeTuple: step must be != 0"); 66 67 static if (step > 0) 68 { 69 static if (stop <= start) 70 alias RangeTuple = Tuple!(); 71 else 72 alias RangeTuple = Tuple!(RangeTuple!(start, stop-step, step), stop-step); 73 } 74 else 75 { 76 static if (stop >= start) 77 alias RangeTuple = Tuple!(); 78 else 79 alias RangeTuple = Tuple!(RangeTuple!(start, stop-step, step), stop-step); 80 } 81 }