Molassembler  3.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ContainerTraits.h
Go to the documentation of this file.
1 
11 #ifndef INCLUDE_MOLASSEMBLER_TEMPLE_CONTAINER_TRAITS_H
12 #define INCLUDE_MOLASSEMBLER_TEMPLE_CONTAINER_TRAITS_H
13 
15 
16 #include <utility>
17 
18 namespace Scine {
19 namespace Molassembler {
20 namespace Temple {
21 namespace Traits {
22 namespace Detail {
23 
24 /* All that is needed for boost's is_detected trickery (minus compatibility for
25  * old compilers), replace as soon as minimum required boost version is >= 1.67
26  */
27 
28 template<class...>
29 struct make_void {
30  using type = void;
31 };
32 
33 template<class T>
34 using detector_t = typename make_void<T>::type;
35 
36 template<class Default, class, template<class...> class, class...>
37 struct detector {
38  using value_t = std::false_type;
39  using type = Default;
40 };
41 
42 template<class Default, template<class...> class Op, class... Args>
43 struct detector<Default, detector_t<Op<Args...> >, Op, Args...> {
44  using value_t = std::true_type;
45  using type = Op<Args...>;
46 };
47 
48 struct nonesuch {};
49 
50 template<template<class...> class Op, class... Args>
51 using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
52 
53 template<template<class...> class Op, class... Args>
54 constexpr bool is_detected_v = is_detected<Op, Args...>::value;
55 
56 template<class Container>
57 using TestHasInsert = decltype(
58  std::declval<Container>().insert(
59  std::declval<getValueType<Container>>()
60  )
61 );
62 
63 template<class Container>
64 using TestHasPushBack = decltype(
65  std::declval<Container>().push_back(
66  std::declval<getValueType<Container>>()
67  )
68 );
69 
70 template<class Container>
71 using TestHasEmplace = decltype(
72  std::declval<Container>().emplace(
73  std::declval<getValueType<Container>>()
74  )
75 );
76 
77 template<class Container>
78 using TestHasEmplaceBack = decltype(
79  std::declval<Container>().emplace_back(
80  std::declval<getValueType<Container>>()
81  )
82 );
83 
84 template<class Container>
85 using TestHasSize = decltype(std::declval<Container>().size());
86 
87 template<class Container>
88 using TestHasReserve = decltype(std::declval<Container>().reserve(0));
89 
90 template<class Container>
91 using TestIsTuplelike = decltype(std::tuple_size<Container>::value);
92 
93 template<class Container>
94 using TestIsPairlike = decltype(std::declval<Container>().first);
95 
96 } // namespace Detail
97 
102 template<class Container>
103 struct hasInsert : std::integral_constant<bool, Detail::is_detected_v<Detail::TestHasInsert, Container>> {};
104 
109 template<class Container>
110 struct hasPushBack : std::integral_constant<bool, Detail::is_detected_v<Detail::TestHasPushBack, Container>> {};
111 
116 template<class Container>
117 struct hasEmplace : std::integral_constant<bool, Detail::is_detected_v<Detail::TestHasEmplace, Container>> {};
118 
123 template<class Container>
124 struct hasEmplaceBack : std::integral_constant<bool, Detail::is_detected_v<Detail::TestHasEmplaceBack, Container>> {};
125 
130 template<class Container>
131 struct hasSize : std::integral_constant<bool, Detail::is_detected_v<Detail::TestHasSize, Container>> {};
132 
137 template<class Container>
138 struct hasReserve : std::integral_constant<bool, Detail::is_detected_v<Detail::TestHasReserve, Container>> {};
139 
144 template<class Container>
145 struct isTuplelike : std::integral_constant<bool, Detail::is_detected_v<Detail::TestIsTuplelike, Container>> {};
146 
151 template<class Container>
152 struct isPairlike : std::integral_constant<bool, Detail::is_detected_v<Detail::TestIsPairlike, Container> && !isTuplelike<Container>::value> {};
153 
154 } // namespace Traits
155 } // namespace Temple
156 } // namespace Molassembler
157 } // namespace Scine
158 
159 #endif
Has a push_back method accepting the container value type.
Definition: ContainerTraits.h:110
Has an emplace method accepting the container value type.
Definition: ContainerTraits.h:117
unsigned size(Shape shape)
Fetch the number of vertices of a shape.
Has a nullary size member.
Definition: ContainerTraits.h:131
Has an emplace_back method accepting the container value type.
Definition: ContainerTraits.h:124
Has first and second members, but no support for std::tuple_size.
Definition: ContainerTraits.h:152
Provides a few basic function and container traits.
Has support for std::tuple_size.
Definition: ContainerTraits.h:145
constexpr Get< 0 > first
Calls std::get&lt;0&gt; on any argument it is invoked with.
Definition: Functor.h:123
Has an insert method accepting the container value type.
Definition: ContainerTraits.h:103
Has a reserve member accepting an integer type.
Definition: ContainerTraits.h:138