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  */
25 
26 #include <vector>
27 #include <set>
28 #include <string>
29 #include <map>
30 
31 namespace armarx::meta
32 {
33  struct Foo {};
34 
35  static_assert(std::is_same<int, first_type<int, long, char>>::value, "first_type broken");
36  static_assert(std::is_same<char, last_type<int, long, char>>::value, "last_type broken");
37 
38  static_assert(std::is_same<void, nth_type<0, void, long, char>>::value, "nth_type broken");
39  static_assert(std::is_same<long, nth_type<1, void, long, char>>::value, "nth_type broken");
40  static_assert(std::is_same<char, nth_type<2, void, long, char>>::value, "nth_type broken");
41 
42  static_assert(std::is_same<void, NthType<0, void, long, char>::type>::value, "NthType broken");
43  static_assert(std::is_same<long, NthType<1, void, long, char>::type>::value, "NthType broken");
44  static_assert(std::is_same<char, NthType<2, void, long, char>::type>::value, "NthType broken");
45 
46  static_assert(std::is_same<void, void_t<>>::value, "void_t broken");
47  static_assert(std::is_same<void, void_t<int>>::value, "void_t broken");
48  static_assert(std::is_same<void, void_t<decltype(1)>>::value, "void_t broken");
49 
50  static_assert(TypeTemplateTraits::IsInstanceOf<std::vector, std::vector<int>>::value, "TypeTemplateTraits::IsInstanceOf broken");
51  static_assert(!TypeTemplateTraits::IsInstanceOf<std::set, std::vector<int>>::value, "TypeTemplateTraits::IsInstanceOf broken");
52 
53  static_assert(std::is_same<void, last_type<int, void>>::value, "last_type broken");
54 
55  static_assert(HasToString<int>::value, "HasToString broken");
56  static_assert(!HasToString<Foo>::value, "HasToString broken");
57 
58  static_assert(HasAtMethod<std::vector<int>, int>::value, "HasAtMethod broken");
59  static_assert(HasAtMethod<std::vector<int>, std::size_t>::value, "HasAtMethod broken");
60  static_assert(HasAtMethod<std::map<std::string, int>, std::string>::value, "HasAtMethod broken");
61  static_assert(!HasAtMethod<std::vector<int>, Foo>::value, "HasAtMethod broken");
62  static_assert(!HasAtMethod<Foo, int>::value, "HasAtMethod broken");
63 
64  // names are describing the memberfunction foo
65  // nonstatic / static (n/s)
66  // return void / char (v/c)
67  // accept void / char (v/c)
68  struct nvv
69  {
70  void foo(void) {}
71  };
72  struct nvc
73  {
74  void foo(char) {}
75  };
76  struct ncv
77  {
78  char foo(void)
79  {
80  return 0;
81  }
82  };
83  struct ncc
84  {
85  char foo(char)
86  {
87  return 0;
88  }
89  };
90  struct svv
91  {
92  static void foo(void) {}
93  };
94  struct svc
95  {
96  static void foo(char) {}
97  };
98  struct scv
99  {
100  static char foo(void)
101  {
102  return 0;
103  }
104  };
105  struct scc
106  {
107  static char foo(char)
108  {
109  return 0;
110  }
111  };
112 
113  ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasFoo, foo, void(T::*)(void));
114  ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasStaticFoo, foo, void(*)(void));
115 
116  static_assert(hasFoo_v<nvv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
117  static_assert(!hasFoo_v<nvc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
118  static_assert(!hasFoo_v<ncv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
119  static_assert(!hasFoo_v<ncc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
120  static_assert(!hasFoo_v<svv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
121  static_assert(!hasFoo_v<svc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
122  static_assert(!hasFoo_v<scv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
123  static_assert(!hasFoo_v<scc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
124 
125  static_assert(!hasStaticFoo_v<nvv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
126  static_assert(!hasStaticFoo_v<nvc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
127  static_assert(!hasStaticFoo_v<ncv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
128  static_assert(!hasStaticFoo_v<ncc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
129  static_assert(hasStaticFoo_v<svv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
130  static_assert(!hasStaticFoo_v<svc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
131  static_assert(!hasStaticFoo_v<scv>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
132  static_assert(!hasStaticFoo_v<scc>, "ERROR ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK");
133 
134  template<class...> struct Template0;
135  template<class...> struct Template1;
136 
137  static_assert(!TypeTemplateTraits::DisassembleTemplate<int>::value, "TypeTemplateTraits::DisassembleTemplate");
138  static_assert(TypeTemplateTraits::DisassembleTemplate<Template0<int, void, char>>::value, "TypeTemplateTraits::DisassembleTemplate");
139  static_assert(
140  std::is_same
141  <
144  >::value, "TypeTemplateTraits::DisassembleTemplate::ReplaceTemplate");
145 
146  static_assert(
147  std::is_same
148  <
151  >::value, "TypeTemplateTraits::DisassembleTemplate::ReplaceParameters");
152 
153 
154  static_assert(std::is_same<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>::value, "MakeIndexSequence broken");
155  static_assert(std::is_same<IndexSequence<0, 1, 2>, MakeIndexSequenceFor<int, int, int>>::value, "MakeIndexSequenceFor broken");
156  static_assert(std::is_same<IndexSequence<2, 3, 4>, MakeIndexRange<2, 5>>::value, "MakeIndexRange broken");
157 
158  template <class T, class U = int>
159  struct DecayAllTest : std::is_same<typename DecayAll<T>::type, U> {};
160 
161  //type
162  static_assert(DecayAllTest<int>::value, "ERROR DecayAll");
163  static_assert(DecayAllTest<int&>::value, "ERROR DecayAll");
164  static_assert(DecayAllTest < int&& >::value, "ERROR DecayAll");
165 
166  static_assert(DecayAllTest<const int>::value, "ERROR DecayAll");
167  static_assert(DecayAllTest<const int&>::value, "ERROR DecayAll");
168  static_assert(DecayAllTest < const int&& >::value, "ERROR DecayAll");
169 
170  static_assert(DecayAllTest<int*>::value, "ERROR DecayAll");
171  static_assert(DecayAllTest<int* const>::value, "ERROR DecayAll");
172 
173  static_assert(DecayAllTest<const int*>::value, "ERROR DecayAll");
174  static_assert(DecayAllTest<const int* const>::value, "ERROR DecayAll");
175 
176  //arrays
177  static_assert(DecayAllTest<int[2]>::value, "ERROR DecayAll");
178  static_assert(DecayAllTest<std::add_lvalue_reference<int[2]>::type>::value, "ERROR DecayAll");
179  static_assert(DecayAllTest<std::add_rvalue_reference<int[2]>::type>::value, "ERROR DecayAll");
180 
181  static_assert(DecayAllTest<const int[2]>::value, "ERROR DecayAll");
182  static_assert(DecayAllTest<const std::add_lvalue_reference<int[2]>::type>::value, "ERROR DecayAll");
183  static_assert(DecayAllTest<const std::add_rvalue_reference<int[2]>::type>::value, "ERROR DecayAll");
184 
185  static_assert(DecayAllTest<int(*)[2]>::value, "ERROR DecayAll");
186  static_assert(DecayAllTest<int(* const)[2]>::value, "ERROR DecayAll");
187 
188  static_assert(DecayAllTest<const int(*)[2]>::value, "ERROR DecayAll");
189  static_assert(DecayAllTest<const int(* const)[2]>::value, "ERROR DecayAll");
190 
191  static_assert(DecayAllTest<int(int), int(*)(int)>::value, "ERROR DecayAll");
192 }
armarx::meta::svc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:94
armarx::meta::DecayAllTest
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:159
armarx::meta::ncv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:76
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:143
armarx::meta
Definition: PluginCfgStruct.h:31
armarx::meta::Template0
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:134
armarx::meta::scv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:98
armarx::meta::NthType
Definition: TemplateMetaProgramming.h:124
armarx::meta::nvc::foo
void foo(char)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:74
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::meta::nvv::foo
void foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:70
armarx::meta::MakeIndexRange
typename detail::MakeIndexRange< Lo, Hi >::type MakeIndexRange
Definition: TemplateMetaProgramming.h:236
armarx::meta::MakeIndexSequenceFor
MakeIndexSequence< sizeof...(Ts)> MakeIndexSequenceFor
Definition: TemplateMetaProgramming.h:239
armarx::meta::ncc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:83
armarx::meta::svv::foo
static void foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:92
armarx::meta::first_type
T0 first_type
Get the type of the first element of a template parameter pack.
Definition: TemplateMetaProgramming.h:110
armarx::meta::nvv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:68
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:135
armarx::meta::TypeTemplateTraits::DisassembleTemplate
Definition: TemplateMetaProgramming.h:88
armarx::meta::HasAtMethod
Can be used to determine if T has an at method accepting a type of IdxT.
Definition: TemplateMetaProgramming.h:163
armarx::meta::void_t
void void_t
Helper for sfinae (is added in c++17)
Definition: TemplateMetaProgramming.h:59
armarx::meta::scv::foo
static char foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:100
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:107
armarx::meta::scc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:105
armarx::meta::svv
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:90
armarx::meta::ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK
ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasFoo, foo, void(T::*)(void))
armarx::meta::nvc
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:72
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::meta::Foo
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:33
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:104
armarx::meta::ncc::foo
char foo(char)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:85
armarx::meta::MakeIndexSequence
typename detail::MakeIndexSequence< N >::type MakeIndexSequence
Definition: TemplateMetaProgramming.h:233
armarx::meta::TypeTemplateTraits::IsInstanceOf
Whether a type T is the instance of a given template Template.
Definition: TemplateMetaProgramming.h:71
armarx::meta::svc::foo
static void foo(char)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:96
armarx::meta::ncv::foo
char foo(void)
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:78
armarx::meta::Template1
Definition: TemplateMetaProgrammingCompileTimeTest.cpp:135
armarx::meta::IndexSequence
Definition: TemplateMetaProgramming.h:194