Apache Mesos
traits.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_TRAITS_HPP__
14 #define __STOUT_TRAITS_HPP__
15 
16 template <typename T, template <typename...> class C>
17 struct is_specialization_of : std::false_type {};
18 
19 template <template <typename...> class C, typename... Args>
20 struct is_specialization_of<C<Args...>, C> : std::true_type {};
21 
22 
23 // Lambda (or functor) traits.
24 template <typename T>
25 struct LambdaTraits : public LambdaTraits<decltype(&T::operator())> {};
26 
27 
28 template <typename Class, typename Result, typename... Args>
29 struct LambdaTraits<Result(Class::*)(Args...) const>
30 {
32 };
33 
34 
35 // Helper for checking if a type `U` is the same as or convertible to
36 // _at least one of_ the types `Ts`.
37 //
38 // Example usage:
39 //
40 // std::enable_if<AtLeastOneIsSameOrConvertible<U, Ts>::value>
41 template <typename...>
43 {
44  static constexpr bool value = false;
45 };
46 
47 
48 template <typename U, typename T, typename... Ts>
49 struct AtLeastOneIsSameOrConvertible<U, T, Ts...>
50 {
51  static constexpr bool value =
52  std::is_same<U, T>::value ||
53  std::is_convertible<U, T>::value ||
54  AtLeastOneIsSameOrConvertible<U, Ts...>::value;
55 };
56 
57 #endif // __STOUT_TRAITS_HPP__
Result result_type
Definition: traits.hpp:31
Definition: check.hpp:30
Definition: traits.hpp:42
Definition: traits.hpp:17
Definition: traits.hpp:25
Class
Definition: elf.hpp:38