Interface Documentation
Version: invalid
type_traits.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include <type_traits>
19 
20 namespace flecsi {
21 namespace util {
22 
24 // A type trait utility to detect if a type is a strict STL container.
26 
27 namespace detail {
28 
29 template<typename... Ts>
30 struct hold {};
31 
32 // Adapted from https://stackoverflow.com/questions/25845536/
33 template<template<class...> class B, class D>
35  template<class... AA>
36  static B<AA...> test(B<AA...> *);
37  static void test(void *);
38 
39  using type = decltype(test(static_cast<D *>(nullptr)));
40 };
41 
42 template<class T>
43 struct nonvoid {
44  using type = T;
45 };
46 template<>
47 struct nonvoid<void> {};
48 
49 } // namespace detail
50 
51 // Workaround for Clang's eager reduction of void_t (see also CWG1980)
52 template<class... TT>
53 using voided = std::conditional_t<false, detail::hold<TT...>, void>;
54 
55 template<template<class...> class B, class D>
57  : detail::nonvoid<typename detail::base_specialization<B, D>::type> {};
58 template<template<class...> class B, class D>
59 using base_specialization_t = typename base_specialization<B, D>::type;
60 
64 template<typename T, typename _ = void>
65 struct is_container : std::false_type {};
66 
70 template<typename T>
71 struct is_container<T,
72  voided<typename T::value_type,
73  typename T::size_type,
74  typename T::allocator_type,
75  typename T::iterator,
76  typename T::const_iterator,
77  decltype(std::declval<T>().size()),
78  decltype(std::declval<T>().begin()),
79  decltype(std::declval<T>().end()),
80  decltype(std::declval<T>().cbegin()),
81  decltype(std::declval<T>().cend()),
82  decltype(std::declval<T>().data())>> : public std::true_type {};
83 
86 template<typename T>
88 
90 // A type trait utility to detect if a type is a minimal container.
91 //
92 // Testing is more relaxed than is_container, it only needs to have a
93 // size and data memeber function..
95 
99 template<typename T, typename _ = void>
100 struct is_minimal_container : std::false_type {};
101 
105 template<typename T>
107  voided<decltype(std::declval<T>().size()),
108  decltype(std::declval<T>().data())>> : public std::true_type {};
109 
112 template<typename T>
114 
116 // A type trait utility to detect if a type is a minimal container.
117 //
118 // Testing is more relaxed than is_container, it only needs to have a
119 // begin and end function.
121 
125 template<typename T, typename _ = void>
126 struct is_iterative_container : std::false_type {};
127 
131 template<typename T>
133  voided<decltype(std::declval<T>().begin()),
134  decltype(std::declval<T>().end())>> : public std::true_type {};
135 
138 template<typename T>
140 
141 } // namespace util
142 } // namespace flecsi
int test(ARGS &&... args)
Definition: execution.hh:411
Definition: type_traits.hh:34
Definition: type_traits.hh:43
constexpr bool is_iterative_container_v
Equal to true if T is a container.
Definition: type_traits.hh:139
A Helper to identify if this is a container.
Definition: type_traits.hh:100
Definition: type_traits.hh:56
constexpr bool is_minimal_container_v
Equal to true if T is a container.
Definition: type_traits.hh:113
A Helper to identify if this is a container.
Definition: type_traits.hh:126
Definition: type_traits.hh:30
Check if a particular type T is a container.
Definition: type_traits.hh:65
constexpr bool is_container_v
Equal to true if T is a container.
Definition: type_traits.hh:87
Definition: control.hh:31