1 | // |
---|
2 | // You received this file as part of RRLib |
---|
3 | // Robotics Research Library |
---|
4 | // |
---|
5 | // Copyright (C) Finroc GbR (finroc.org) |
---|
6 | // |
---|
7 | // This program is free software; you can redistribute it and/or |
---|
8 | // modify it under the terms of the GNU General Public License |
---|
9 | // as published by the Free Software Foundation; either version 2 |
---|
10 | // of the License, or (at your option) any later version. |
---|
11 | // |
---|
12 | // This program is distributed in the hope that it will be useful, |
---|
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | // GNU General Public License for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License |
---|
18 | // along with this program; if not, write to the Free Software |
---|
19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
20 | // |
---|
21 | //---------------------------------------------------------------------- |
---|
22 | /*!\file tMostDerived.h |
---|
23 | * |
---|
24 | * \author Tobias Foehst |
---|
25 | * |
---|
26 | * \date 2011-03-25 |
---|
27 | * |
---|
28 | * \brief Contains tMostDerived |
---|
29 | * |
---|
30 | * \b tMostDerived |
---|
31 | * |
---|
32 | */ |
---|
33 | //---------------------------------------------------------------------- |
---|
34 | #ifndef __rrlib__util__type_list__include_guard__ |
---|
35 | #error Invalid include directive. Try #include "rrlib/util/tTypeList.h" instead. |
---|
36 | #endif |
---|
37 | |
---|
38 | #ifndef __rrlib__util__type_lists__tMostDerived_h__ |
---|
39 | #define __rrlib__util__type_lists__tMostDerived_h__ |
---|
40 | |
---|
41 | //---------------------------------------------------------------------- |
---|
42 | // External includes (system with <>, local with "") |
---|
43 | //---------------------------------------------------------------------- |
---|
44 | #include <type_traits> |
---|
45 | |
---|
46 | //---------------------------------------------------------------------- |
---|
47 | // Internal includes with "" |
---|
48 | //---------------------------------------------------------------------- |
---|
49 | |
---|
50 | //---------------------------------------------------------------------- |
---|
51 | // Debugging |
---|
52 | //---------------------------------------------------------------------- |
---|
53 | |
---|
54 | //---------------------------------------------------------------------- |
---|
55 | // Namespace declaration |
---|
56 | //---------------------------------------------------------------------- |
---|
57 | namespace rrlib |
---|
58 | { |
---|
59 | namespace util |
---|
60 | { |
---|
61 | namespace type_list |
---|
62 | { |
---|
63 | |
---|
64 | //---------------------------------------------------------------------- |
---|
65 | // Forward declarations / typedefs / enums |
---|
66 | //---------------------------------------------------------------------- |
---|
67 | |
---|
68 | //---------------------------------------------------------------------- |
---|
69 | // Class declaration |
---|
70 | //---------------------------------------------------------------------- |
---|
71 | //! |
---|
72 | /*! |
---|
73 | * |
---|
74 | */ |
---|
75 | namespace |
---|
76 | { |
---|
77 | |
---|
78 | template <bool, typename TThen, typename TElse> |
---|
79 | struct tIfThenElse |
---|
80 | { |
---|
81 | typedef TThen tResult; |
---|
82 | }; |
---|
83 | |
---|
84 | template <typename TThen, typename TElse> |
---|
85 | struct tIfThenElse<false, TThen, TElse> |
---|
86 | { |
---|
87 | typedef TElse tResult; |
---|
88 | }; |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | template <typename TList, typename TBase> |
---|
93 | class tMostDerived |
---|
94 | { |
---|
95 | typedef typename tMostDerived<typename TList::tTail, TBase>::tResult tCandidate; |
---|
96 | static const bool cHEAD_DERIVED_FROM_CANDIDATE = std::is_base_of<tCandidate, typename TList::tHead>::value; |
---|
97 | public: |
---|
98 | typedef typename tIfThenElse<cHEAD_DERIVED_FROM_CANDIDATE, typename TList::tHead, tCandidate>::tResult tResult; |
---|
99 | }; |
---|
100 | |
---|
101 | template <typename TBase> |
---|
102 | struct tMostDerived<tEmptyList, TBase> |
---|
103 | { |
---|
104 | typedef TBase tResult; |
---|
105 | }; |
---|
106 | |
---|
107 | //---------------------------------------------------------------------- |
---|
108 | // End of namespace declartMostDerivedion |
---|
109 | //---------------------------------------------------------------------- |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | #endif |
---|