Add tanya.typecons.Pair

This commit is contained in:
Eugen Wissner 2017-05-19 21:15:56 +02:00
parent a648e2120a
commit ba0aff6737
1 changed files with 41 additions and 0 deletions

41
source/tanya/typecons.d Normal file
View File

@ -0,0 +1,41 @@
/* 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/. */
/**
* Type constructors.
*
* Copyright: Eugene Wissner 2017.
* 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.typecons;
import std.meta;
/**
* $(D_PSYMBOL Pair) can store two heterogeneous objects. The objects can be
* accessed than by the index. The objects can by accessed by index as
* $(D_INLINECODE obj[0]) and $(D_INLINECODE obj[1]).
*/
template Pair(Field1, Field2)
{
/// Field types.
alias Types = AliasSeq!(Field1, Field2);
struct Pair
{
/// Represents the values of the $(D_PSYMBOL Pair) as a list of values.
Types expand;
alias expand this;
}
}
///
unittest
{
static assert(is(Pair!(int, int)));
static assert(!is(Pair!(int, 5)));
}