TemplateMetaProgrammingCompileTimeTest.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu)
20  * @date 2017
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include <map>
25 #include <set>
26 #include <string>
27 #include <vector>
28 
30 
31 namespace armarx::meta
32 {
33  struct Foo
34  {
35  };
36 
37  static_assert(std::is_same<int, first_type<int, long, char>>::value, "first_type broken");
38  static_assert(std::is_same<char, last_type<int, long, char>>::value, "last_type broken");
39 
40  static_assert(std::is_same<void, nth_type<0, void, long, char>>::value, "nth_type broken");
41  static_assert(std::is_same<long, nth_type<1, void, long, char>>::value, "nth_type broken");
42  static_assert(std::is_same<char, nth_type<2, void, long, char>>::value, "nth_type broken");
43 
44  static_assert(std::is_same<void, NthType<0, void, long, char>::type>::value, "NthType broken");
45  static_assert(std::is_same<long, NthType<1, void, long, char>::type>::value, "NthType broken");
46  static_assert(std::is_same<char, NthType<2, void, long, char>::type>::value, "NthType broken");
47 
48  static_assert(std::is_same<void, void_t<>>::value, "void_t broken");
49  static_assert(std::is_same<void, void_t<int>>::value, "void_t broken");
50  static_assert(std::is_same<void, void_t<decltype(1)>>::value, "void_t broken");
51 
52  static_assert(TypeTemplateTraits::IsInstanceOf<std::vector, std::vector<int>>::value,
53  "TypeTemplateTraits::IsInstanceOf broken");
54  static_assert(!TypeTemplateTraits::IsInstanceOf<std::set, std::vector<int>>::value,
55  "TypeTemplateTraits::IsInstanceOf broken");
56 
57  static_assert(std::is_same<void, last_type<int, void>>::value, "last_type broken");
58 
59  static_assert(HasToString<int>::value, "HasToString broken");
60  static_assert(!HasToString<Foo>::value, "HasToString broken");
61 
62  static_assert(HasAtMethod<std::vector<int>, int>::value, "HasAtMethod broken");
63  static_assert(HasAtMethod<std::vector<int>, std::size_t>::value, "HasAtMethod broken");
64  static_assert(HasAtMethod<std::map<std::string, int>, std::string>::value,
65  "HasAtMethod broken");
66  static_assert(!HasAtMethod<std::vector<int>, Foo>::value, "HasAtMethod broken");
67  static_assert(!HasAtMethod<Foo, int>::value, "HasAtMethod broken");
68 
69  // names are describing the memberfunction foo
70  // nonstatic / static (n/s)
71  // return void / char (v/c)
72  // accept void / char (v/c)
73  struct nvv
74  {
75  void
76  foo(void)
77  {
78  }
79  };
80 
81  struct nvc
82  {
83  void
84  foo(char)
85  {
86  }
87  };
88 
89  struct ncv
90  {
91  char
92  foo(void)
93  {
94  return 0;
95  }
96  };
97 
98  struct ncc
99  {
100  char
101  foo(char)
102  {
103  return 0;
104  }
105  };
106 
107  struct svv
108  {
109  static void
110  foo(void)
111  {
112  }
113  };
114 
115  struct svc
116  {
117  static void
118  foo(char)
119  {
120  }
121  };
122 
123  struct scv
124  {
125  static char
126  foo(void)
127  {
128  return 0;
129  }
130  };
131 
132  struct scc
133  {
134  static char
135  foo(char)
136  {
137  return 0;
138  }
139  };
140 
141  ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasFoo, foo, void (T::*)(void));
142  ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasStaticFoo, foo, void (*)(void));
143 
144  static_assert(hasFoo_v<nvv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
145  static_assert(!hasFoo_v<nvc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
146  static_assert(!hasFoo_v<ncv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
147  static_assert(!hasFoo_v<ncc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
148  static_assert(!hasFoo_v<svv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
149  static_assert(!hasFoo_v<svc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
150  static_assert(!hasFoo_v<scv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
151  static_assert(!hasFoo_v<scc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
152 
153  static_assert(!hasStaticFoo_v<nvv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
154  static_assert(!hasStaticFoo_v<nvc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
155  static_assert(!hasStaticFoo_v<ncv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
156  static_assert(!hasStaticFoo_v<ncc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
157  static_assert(hasStaticFoo_v<svv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
158  static_assert(!hasStaticFoo_v<svc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
159  static_assert(!hasStaticFoo_v<scv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
160  static_assert(!hasStaticFoo_v<scc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
161 
162  template <class...>
163  struct Template0;
164  template <class...>
165  struct Template1;
166 
168  "TypeTemplateTraits::DisassembleTemplate");
170  "TypeTemplateTraits::DisassembleTemplate");
171  static_assert(std::is_same<TypeTemplateTraits::DisassembleTemplate<
172  Template0<int, void, char>>::ReplaceTemplate<Template1>,
174  "TypeTemplateTraits::DisassembleTemplate::ReplaceTemplate");
175 
176  static_assert(std::is_same<TypeTemplateTraits::DisassembleTemplate<
177  Template0<int, void, char>>::ReplaceParameters<void>,
179  "TypeTemplateTraits::DisassembleTemplate::ReplaceParameters");
180 
181 
182  static_assert(std::is_same<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>::value,
183  "MakeIndexSequence broken");
185  "MakeIndexSequenceFor broken");
186  static_assert(std::is_same<IndexSequence<2, 3, 4>, MakeIndexRange<2, 5>>::value,
187  "MakeIndexRange broken");
188 
189  template <class T, class U = int>
190  struct DecayAllTest : std::is_same<typename DecayAll<T>::type, U>
191  {
192  };
193 
194  //type
195  static_assert(DecayAllTest<int>::value, "ERROR DecayAll");
196  static_assert(DecayAllTest<int&>::value, "ERROR DecayAll");
197  static_assert(DecayAllTest<int&&>::value, "ERROR DecayAll");
198 
199  static_assert(DecayAllTest<const int>::value, "ERROR DecayAll");
200  static_assert(DecayAllTest<const int&>::value, "ERROR DecayAll");
201  static_assert(DecayAllTest<const int&&>::value, "ERROR DecayAll");
202 
203  static_assert(DecayAllTest<int*>::value, "ERROR DecayAll");
204  static_assert(DecayAllTest<int* const>::value, "ERROR DecayAll");
205 
206  static_assert(DecayAllTest<const int*>::value, "ERROR DecayAll");
207  static_assert(DecayAllTest<const int* const>::value, "ERROR DecayAll");
208 
209  //arrays
210  static_assert(DecayAllTest<int[2]>::value, "ERROR DecayAll");
211  static_assert(DecayAllTest<std::add_lvalue_reference<int[2]>::type>::value, "ERROR DecayAll");
212  static_assert(DecayAllTest<std::add_rvalue_reference<int[2]>::type>::value, "ERROR DecayAll");
213 
214  static_assert(DecayAllTest<const int[2]>::value, "ERROR DecayAll");
215  static_assert(DecayAllTest<const std::add_lvalue_reference<int[2]>::type>::value,
216  "ERROR DecayAll");
217  static_assert(DecayAllTest<const std::add_rvalue_reference<int[2]>::type>::value,
218  "ERROR DecayAll");
219 
220  static_assert(DecayAllTest<int (*)[2]>::value, "ERROR DecayAll");
221  static_assert(DecayAllTest<int (*const)[2]>::value, "ERROR DecayAll");
222 
223  static_assert(DecayAllTest<const int (*)[2]>::value, "ERROR DecayAll");
224  static_assert(DecayAllTest<const int (*const)[2]>::value, "ERROR DecayAll");
225 
226  static_assert(DecayAllTest<int(int), int (*)(int)>::value, "ERROR DecayAll");
227 } // namespace armarx::meta
armarx::meta::svc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:115
armarx::meta::DecayAllTest
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:190
armarx::meta::nth_type
typename std::decay< typename std::tuple_element< n, std::tuple< T0, Ts... > >::type >::type nth_type
Get the type of the nth element of a template parameter pack.
Definition: TemplateMetaProgramming.h:154
armarx::meta::ncv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:89
TemplateMetaProgramming.h
armarx::meta::HasToString
Can be used to determine if there is an overload for std::to_string for a type T.
Definition: TemplateMetaProgramming.h:162
armarx::meta
Definition: PluginCfgStruct.h:31
armarx::meta::Template0
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:163
armarx::meta::scv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:123
armarx::meta::NthType
Definition: TemplateMetaProgramming.h:138
armarx::meta::nvc::foo
void foo(char)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:84
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::meta::nvv::foo
void foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:76
armarx::meta::MakeIndexRange
typename detail::MakeIndexRange< Lo, Hi >::type MakeIndexRange
Definition: TemplateMetaProgramming.h:294
armarx::meta::MakeIndexSequenceFor
MakeIndexSequence< sizeof...(Ts)> MakeIndexSequenceFor
Definition: TemplateMetaProgramming.h:297
armarx::meta::ncc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:98
armarx::meta::svv::foo
static void foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:110
armarx::meta::first_type
T0 first_type
Get the type of the first element of a template parameter pack.
Definition: TemplateMetaProgramming.h:125
armarx::meta::nvv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:73
armarx::meta::TypeTemplateTraits::DisassembleTemplate
Definition: TemplateMetaProgramming.h:99
armarx::meta::HasAtMethod
Can be used to determine if T has an at method accepting a type of IdxT.
Definition: TemplateMetaProgramming.h:190
armarx::meta::void_t
void void_t
Helper for sfinae (is added in c++17)
Definition: TemplateMetaProgramming.h:62
armarx::meta::scv::foo
static char foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:126
set
set(LIBS ArmarXCoreInterfaces ${CMAKE_THREAD_LIBS_INIT} ${dl_LIBRARIES} ${rt_LIBRARIES} ${QT_LIBRARIES} ${Boost_LIBRARIES} BoostAssertionHandler ArmarXCPPUtility SimoxUtility) set(LIB_FILES ArmarXManager.cpp ArmarXMultipleObjectsScheduler.cpp ArmarXObjectScheduler.cpp ManagedIceObject.cpp ManagedIceObjectPlugin.cpp Component.cpp ComponentPlugin.cpp IceGridAdmin.cpp ArmarXObjectObserver.cpp IceManager.cpp PackagePath.cpp RemoteReferenceCount.cpp logging/LoggingUtil.cpp logging/Logging.cpp logging/LogSender.cpp logging/ArmarXLogBuf.cpp system/ArmarXDataPath.cpp system/DynamicLibrary.cpp system/ProcessWatcher.cpp system/FactoryCollectionBase.cpp system/cmake/CMakePackageFinder.cpp system/cmake/CMakePackageFinderCache.cpp system/cmake/ArmarXPackageToolInterface.cpp system/RemoteObjectNode.cpp services/sharedmemory/HardwareId.cpp services/tasks/RunningTask.cpp services/tasks/ThreadList.cpp services/tasks/ThreadPool.cpp services/profiler/Profiler.cpp services/profiler/FileLoggingStrategy.cpp services/profiler/IceLoggingStrategy.cpp application/Application.cpp application/ApplicationOptions.cpp application/ApplicationProcessFacet.cpp application/ApplicationNetworkStats.cpp application/properties/PropertyUser.cpp application/properties/Property.cpp application/properties/PropertyDefinition.cpp application/properties/PropertyDefinitionContainer.cpp application/properties/PropertyDefinitionHelpFormatter.cpp application/properties/PropertyDefinitionConfigFormatter.cpp application/properties/PropertyDefinitionBriefHelpFormatter.cpp application/properties/PropertyDefinitionXmlFormatter.cpp application/properties/PropertyDefinitionDoxygenFormatter.cpp application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.cpp application/properties/PropertyDefinitionContainerBriefHelpFormatter.cpp application/properties/IceProperties.cpp exceptions/Exception.cpp exceptions/local/UnexpectedEnumValueException.cpp util/FileSystemPathBuilder.cpp util/StringHelpers.cpp util/IceReportSkipper.cpp util/Throttler.cpp util/distributed/AMDCallbackCollection.cpp util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.cpp util/distributed/RemoteHandle/RemoteHandle.cpp util/distributed/RemoteHandle/RemoteHandleControlBlock.cpp time/ice_conversions.cpp time/json_conversions.cpp time/CallbackWaitLock.cpp time/Clock.cpp time/ClockType.cpp time/ClockTypeNames.cpp time/CycleUtil.cpp time/DateTime.cpp time/Duration.cpp time/Frequency.cpp time/LocalTimeServer.cpp time/Metronome.cpp time/ScopedStopWatch.cpp time/StopWatch.cpp time/Timer.cpp time/TimeKeeper.cpp time/TimeUtil.cpp csv/CsvWriter.cpp csv/CsvReader.cpp eigen/conversions.cpp eigen/ice_conversions.cpp) set(LIB_HEADERS ArmarXManager.h ArmarXDummyManager.h ArmarXMultipleObjectsScheduler.h ArmarXObjectObserver.h ArmarXObjectScheduler.h ArmarXFwd.h Component.h ComponentPlugin.h ComponentFactories.h CoreObjectFactories.h IceGridAdmin.h IceManager.h IceManagerImpl.h json_conversions.h ManagedIceObject.h ManagedIceObjectPlugin.h ManagedIceObjectImpl.h ManagedIceObjectDependency.h ManagedIceObjectRegistryInterface.h PackagePath.h RemoteReferenceCount.h system/ImportExport.h system/ImportExportComponent.h system/AbstractFactoryMethod.h system/FactoryCollectionBase.h system/Synchronization.h system/ArmarXDataPath.h system/DynamicLibrary.h system/ProcessWatcher.h system/ConditionSynchronization.h system/cmake/CMakePackageFinder.h system/cmake/CMakePackageFinderCache.h system/cmake/FindPackageX.cmake system/cmake/ArmarXPackageToolInterface.h system/RemoteObjectNode.h logging/LoggingUtil.h logging/LogSender.h logging/Logging.h logging/ArmarXLogBuf.h logging/SpamFilterData.h services/tasks/RunningTask.h services/tasks/PeriodicTask.h services/tasks/ThreadList.h services/tasks/TaskUtil.h services/tasks/ThreadPool.h services/sharedmemory/SharedMemoryProvider.h services/sharedmemory/SharedMemoryConsumer.h services/sharedmemory/IceSharedMemoryProvider.h services/sharedmemory/IceSharedMemoryConsumer.h services/sharedmemory/HardwareIdentifierProvider.h services/sharedmemory/HardwareId.h services/sharedmemory/exceptions/SharedMemoryExceptions.h services/profiler/Profiler.h services/profiler/LoggingStrategy.h services/profiler/FileLoggingStrategy.h services/profiler/IceLoggingStrategy.h application/Application.h application/ApplicationOptions.h application/ApplicationProcessFacet.h application/ApplicationNetworkStats.h application/properties/forward_declarations.h application/properties/Properties.h application/properties/Property.h application/properties/PluginEigen.h application/properties/PluginEnumNames.h application/properties/PluginCfgStruct.h application/properties/PluginAll.h application/properties/PropertyUser.h application/properties/PropertyDefinition.h application/properties/PropertyDefinition.hpp application/properties/PropertyDefinitionInterface.h application/properties/PropertyDefinitionContainer.h application/properties/PropertyDefinitionFormatter.h application/properties/PropertyDefinitionContainerFormatter.h application/properties/PropertyDefinitionConfigFormatter.h application/properties/PropertyDefinitionHelpFormatter.h application/properties/PropertyDefinitionBriefHelpFormatter.h application/properties/PropertyDefinitionXmlFormatter.h application/properties/PropertyDefinitionDoxygenFormatter.h application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.h application/properties/PropertyDefinitionContainerBriefHelpFormatter.h application/properties/ProxyPropertyDefinition.h application/properties/IceProperties.h exceptions/Exception.h exceptions/LocalException.h exceptions/local/DynamicLibraryException.h exceptions/local/ExpressionException.h exceptions/local/FileIOException.h exceptions/local/InvalidPropertyValueException.h exceptions/local/MissingRequiredPropertyException.h exceptions/local/PropertyInheritanceCycleException.h exceptions/local/ProxyNotInitializedException.h exceptions/local/UnexpectedEnumValueException.h exceptions/local/UnmappedValueException.h exceptions/local/ValueRangeExceededException.h exceptions/user/NotImplementedYetException.h rapidxml/rapidxml.hpp rapidxml/rapidxml_print.hpp rapidxml/rapidxml_iterators.hpp rapidxml/rapidxml_utils.hpp rapidxml/wrapper/RapidXmlReader.h rapidxml/wrapper/RapidXmlWriter.h rapidxml/wrapper/DefaultRapidXmlReader.h rapidxml/wrapper/MultiNodeRapidXMLReader.h util/IceBlobToObject.h util/ObjectToIceBlob.h util/FileSystemPathBuilder.h util/FiniteStateMachine.h util/StringHelpers.h util/StringHelperTemplates.h util/algorithm.h util/OnScopeExit.h util/Predicates.h util/Preprocessor.h util/PropagateConst.h util/Registrar.h util/TemplateMetaProgramming.h util/TripleBuffer.h util/IceReportSkipper.h util/Throttler.h util/distributed/AMDCallbackCollection.h util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h util/distributed/RemoteHandle/RemoteHandle.h util/distributed/RemoteHandle/RemoteHandleControlBlock.h util/SimpleStatemachine.h time.h time_minimal.h time/forward_declarations.h time/ice_conversions.h time/json_conversions.h time/CallbackWaitLock.h time/Clock.h time/ClockType.h time/ClockTypeNames.h time/CycleUtil.h time/DateTime.h time/Duration.h time/Frequency.h time/LocalTimeServer.h time/Metronome.h time/ScopedStopWatch.h time/StopWatch.h time/Timer.h time/TimeUtil.h time/TimeKeeper.h csv/CsvWriter.h csv/CsvReader.h eigen/conversions.h eigen/ice_conversions.h ice_conversions.h ice_conversions/ice_conversions_boost_templates.h ice_conversions/ice_conversions_templates.h ice_conversions/ice_conversions_templates.tpp $
Definition: CMakeLists.txt:12
armarx::meta::scc::foo
static char foo(char)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:135
armarx::meta::scc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:132
armarx::meta::svv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:107
armarx::meta::ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK
ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasFoo, foo, void(T::*)(void))
armarx::meta::last_type
typename std::decay< typename std::tuple_element< sizeof...(Ts), std::tuple< T0, Ts... > >::type >::type last_type
Get the type of the last element of a template parameter pack.
Definition: TemplateMetaProgramming.h:119
armarx::meta::nvc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:81
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
armarx::meta::Foo
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:33
armarx::meta::ncc::foo
char foo(char)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:101
armarx::meta::MakeIndexSequence
typename detail::MakeIndexSequence< N >::type MakeIndexSequence
Definition: TemplateMetaProgramming.h:291
armarx::meta::TypeTemplateTraits::IsInstanceOf
Whether a type T is the instance of a given template Template.
Definition: TemplateMetaProgramming.h:75
armarx::meta::svc::foo
static void foo(char)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:118
armarx::meta::ncv::foo
char foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:92
armarx::meta::Template1
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:165
armarx::meta::IndexSequence
Definition: TemplateMetaProgramming.h:236