Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tmeta.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/common/tmeta.hpp
3  *
4  * Template Metaprogramming Tools
5  * (from the Generative Programming book Krysztof Czarnecki, Ulrich Eisenecker)
6  *
7  * Part of FOXXLL. See http://foxxll.org
8  *
9  * Copyright (C) 2003 Roman Dementiev <[email protected]>
10  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
11  *
12  * Distributed under the Boost Software License, Version 1.0.
13  * (See accompanying file LICENSE_1_0.txt or copy at
14  * http://www.boost.org/LICENSE_1_0.txt)
15  **************************************************************************/
16 
17 #ifndef FOXXLL_COMMON_TMETA_HEADER
18 #define FOXXLL_COMMON_TMETA_HEADER
19 
20 #include <type_traits>
21 
22 #include <foxxll/common/types.hpp>
23 
24 namespace foxxll {
25 
26 const int DEFAULT = ~(~0u >> 1); // initialize with the smallest int
27 
28 struct NilCase { };
29 
30 template <int Tag, class Type_, class Next_ = NilCase>
31 struct CASE
32 {
33  enum { tag = Tag };
34  using Type = Type_;
35  using Next = Next_;
36 };
37 
38 template <int Tag, class Case>
39 class SWITCH
40 {
41  using NextCase = typename Case::Next;
42  enum
43  {
44  caseTag = Case::tag,
45  found = (caseTag == Tag || caseTag == DEFAULT)
46  };
47 
48 public:
49  using type = typename std::conditional<
50  found,
51  typename Case::Type,
54 };
55 
56 template <int Tag>
57 class SWITCH<Tag, NilCase>
58 {
59 public:
60  using type = NilCase;
61 };
62 
63 } // namespace foxxll
64 
65 #endif // !FOXXLL_COMMON_TMETA_HEADER
66 
67 /**************************************************************************/
Type
VFS object type.
Definition: file_io.hpp:52
typename std::conditional< found, typename Case::Type, typename SWITCH< Tag, NextCase >::type >::type type
Definition: tmeta.hpp:53
Next_ Next
Definition: tmeta.hpp:35
const int DEFAULT
Definition: tmeta.hpp:26
typename Case::Next NextCase
Definition: tmeta.hpp:41
Type_ Type
Definition: tmeta.hpp:34