LeechCraft  0.6.70-6645-gcd10d7e
Modular cross-platform feature rich live environment.
typelist.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include "oldcppkludges.h"
33 
34 namespace LeechCraft
35 {
36 namespace Util
37 {
38  template<typename...>
39  struct Typelist
40  {
41  };
42 
43  template<template<typename...> class List, typename H, typename... T>
44  constexpr List<T...> Tail (List<H, T...>)
45  {
46  return {};
47  }
48 
49  namespace detail
50  {
51  template<int N, typename List>
52  struct DropImpl
53  {
54  using Result_t = typename DropImpl<N - 1, decltype (Tail (List {}))>::Result_t;
55  };
56 
57  template<typename List>
58  struct DropImpl<0, List>
59  {
60  using Result_t = List;
61  };
62  }
63 
64  template<int N, template<typename...> class List, typename... Args>
65  constexpr typename detail::DropImpl<N, List<Args...>>::Result_t Drop (List<Args...>)
66  {
67  return {};
68  }
69 
70  template<template<typename...> class List, typename... Args1, typename... Args2>
71  constexpr List<Args1..., Args2...> Concat (List<Args1...>, List<Args2...>)
72  {
73  return {};
74  }
75 
76  template<template<typename...> class List>
77  constexpr List<> Reverse (List<>)
78  {
79  return {};
80  }
81 
82  template<template<typename...> class List, typename Head, typename... Tail>
83  constexpr auto Reverse (List<Head, Tail...>) -> decltype (Concat (Reverse (List<Tail...> {}), List<Head> {}))
84  {
85  return {};
86  }
87 
88  template<template<typename...> class List, typename... Args>
89  constexpr auto Init (List<Args...>) -> decltype (Reverse (Tail (Reverse (List<Args...> {}))))
90  {
91  return {};
92  }
93 
94  namespace detail
95  {
96  template<typename Type, template<typename...> class List, typename... Tail>
97  constexpr bool HasTypeImpl (List<Type, Tail...>, int)
98  {
99  return true;
100  }
101 
102  template<typename, template<typename...> class List>
103  constexpr bool HasTypeImpl (List<>, float)
104  {
105  return false;
106  }
107 
108  template<typename Type, template<typename...> class List, typename Head, typename... Tail>
109  constexpr bool HasTypeImpl (List<Head, Tail...>, float)
110  {
111  return HasTypeImpl<Type> (List<Tail...> {}, 0);
112  }
113  }
114 
115  template<typename Type, template<typename...> class List, typename... Args>
116  constexpr bool HasType (List<Args...> list)
117  {
118  return detail::HasTypeImpl<Type> (list, 0);
119  }
120 
121  namespace detail
122  {
123  template<template<typename> class, typename, typename = void>
124  struct Filter;
125  }
126 
127  template<template<typename> class Pred, typename List>
128  using Filter_t = typename detail::Filter<Pred, List>::Result_t;
129 
130  namespace detail
131  {
132  template<template<typename> class Pred, template<typename...> class List, typename Head, typename... Tail>
133  struct Filter<Pred, List<Head, Tail...>, EnableIf_t<Pred<Head>::value>>
134  {
135  using Result_t = decltype (Concat (List<Head> {}, Filter_t<Pred, List<Tail...>> {}));
136  };
137 
138  template<template<typename> class Pred, template<typename...> class List, typename Head, typename... Tail>
139  struct Filter<Pred, List<Head, Tail...>, EnableIf_t<!Pred<Head>::value>>
140  {
141  using Result_t = Filter_t<Pred, List<Tail...>>;
142  };
143 
144  template<template<typename> class Pred, template<typename...> class List>
145  struct Filter<Pred, List<>>
146  {
147  using Result_t = List<>;
148  };
149  }
150 
151  template<typename T>
152  struct AsTypelist;
153 
154  template<template<typename...> class OtherList, typename... Args>
155  struct AsTypelist<OtherList<Args...>>
156  {
157  using Result_t = Typelist<Args...>;
158  };
159 
160  template<typename T>
162 }
163 }
constexpr List< T... > Tail(List< H, T... >)
Definition: typelist.h:44
constexpr List Reverse(List<>)
Definition: typelist.h:77
Container< T > Concat(const Container< Container< T >> &containers)
Definition: prelude.h:201
typename DropImpl< N-1, decltype(Tail(List{}))>::Result_t Result_t
Definition: typelist.h:54
typename std::enable_if< B, T >::type EnableIf_t
Definition: oldcppkludges.h:67
Type
Describes the various types of XDG .desktop files.
Definition: itemtypes.h:48
Container< T > Filter(const Container< T > &c, F f)
Definition: prelude.h:191
constexpr detail::DropImpl< N, List< Args... > >::Result_t Drop(List< Args... >)
Definition: typelist.h:65
decltype(Concat(List< Head >{}, Filter_t< Pred, List< Tail... >>{})) Result_t
Definition: typelist.h:135
typename AsTypelist< T >::Result_t AsTypelist_t
Definition: typelist.h:161