From 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 23 Nov 2016 19:09:09 +0900 Subject: Imported Upstream version 1.1.0 --- src/inc/mpl/type_list | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/inc/mpl/type_list (limited to 'src/inc/mpl') diff --git a/src/inc/mpl/type_list b/src/inc/mpl/type_list new file mode 100644 index 0000000000..9073c5e8d0 --- /dev/null +++ b/src/inc/mpl/type_list @@ -0,0 +1,76 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// +// Used in template metaprogramming, type lists consist of a series of +// Scheme-like nodes that contain a Head type and a Tail type. The head +// type is usually a non-list type, but compound lists are possible. +// +// Type lists are always terminated with a tail type of mpl::null_type. +// + +#ifndef __type_list__ +#define __type_list__ + +namespace mpl // 'mpl' => 'meta-programming library' +{ + // Used as terminator in type_lists. + class null_type {}; + + // The core type. See file comment for details. + template + struct type_list + { + typedef T head; + typedef U tail; + }; + + template + struct type_at; + + template + struct type_at, IDX> + { typedef typename type_at::type type; }; + + template + struct type_at, 0> + { typedef head type; }; + + // Helper struct to create a type_list chain from a list of arguments. + template + < + typename T1 = null_type, typename T2 = null_type, typename T3 = null_type, + typename T4 = null_type, typename T5 = null_type, typename T6 = null_type, + typename T7 = null_type, typename T8 = null_type, typename T9 = null_type, + typename T10 = null_type, typename T11 = null_type, typename T12 = null_type, + typename T13 = null_type, typename T14 = null_type, typename T15 = null_type, + typename T16 = null_type, typename T17 = null_type, typename T18 = null_type + > + struct make_type_list + { + private: + // recurse on the tail elements + typedef typename make_type_list::type tail; + + public: + // combine head with computed tail + typedef type_list type; + }; + + template<> + struct make_type_list + < + null_type, null_type, null_type, null_type, null_type, null_type, + null_type, null_type, null_type, null_type, null_type, null_type, + null_type, null_type, null_type, null_type, null_type, null_type + > + { + public: + typedef null_type type; + }; +} + +#endif // __type_list__ + -- cgit v1.2.3