coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
traits.h
Go to the documentation of this file.
1 #ifndef TRAITS_H
2 #define TRAITS_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2013 Mike Kinghan, imk@burroingroingjoing.com *
6  * All rights reserved. *
7  * *
8  * Contributed originally by Mike Kinghan, imk@burroingroingjoing.com *
9  * *
10  * Redistribution and use in source and binary forms, with or without *
11  * modification, are permitted provided that the following conditions *
12  * are met: *
13  * *
14  * Redistributions of source code must retain the above copyright *
15  * notice, this list of conditions and the following disclaimer. *
16  * *
17  * Redistributions in binary form must reproduce the above copyright *
18  * notice, this list of conditions and the following disclaimer in the *
19  * documentation and/or other materials provided with the distribution. *
20  * *
21  * Neither the name of Mike Kinghan nor the names of its contributors *
22  * may be used to endorse or promote products derived from this software *
23  * without specific prior written permission. *
24  * *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
32  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
34  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
35  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
36  * DAMAGE. *
37  * *
38  **************************************************************************/
39 #include <type_traits>
40 #include <cstddef>
41 
46 namespace traits {
47 
48 using std::is_same;
49 using std::declval;
50 
55 template<typename T, typename V>
57 {
59  template<typename A>
60  static constexpr bool test(typename A::value_type * ptr) {
61  return is_same<decltype(ptr),V *>::value;
62  }
63  static constexpr bool test(...) {
64  return false;
65  }
66  static const bool value = test<T>(nullptr);
68 };
69 
70 
75 template<typename T>
77 {
79  template<typename A>
80  static constexpr bool test(decltype(declval<A>().size()) * ptr) {
81  return is_same<decltype(ptr),size_t *>::value;
82  }
83  static constexpr bool test(...) {
84  return false;
85  }
86 
87  static const bool value = test<T>(nullptr);
89 };
90 
95 template< typename T>
97 {
99  template<typename A>
100  static constexpr
101  auto test( decltype(&declval<A>()[size_t(0)]) ptr) ->
102  decltype(is_same<decltype(*ptr),typename A::value_type &>::value)
103  {
104  return is_same<decltype(*ptr),typename A::value_type &>::value;
105  }
106 
107  static constexpr bool test(...) {
108  return false;
109  }
110 
111  static const bool value = test<T>(nullptr);
113 };
114 
119 template< typename T>
121 {
123  template<typename A>
124  static constexpr auto test(decltype(declval<A const>().data()) ptr) ->
125  decltype(is_same<decltype(ptr),typename A::value_type const *>::value)
126  {
127  return is_same<decltype(ptr),typename A::value_type const *>::value;
128  }
129 
130  static constexpr bool test(...) {
131  return false;
132  }
133 
134  static const bool value = test<T>(nullptr);
136 };
137 
142 template< typename T>
144 {
146  template<typename A>
147  static constexpr bool test(decltype(declval<A>().extend()) * ptr) {
148  return is_same<decltype(ptr),size_t *>::value;
149  }
150 
151  template<typename A>
152  static constexpr bool test(...) {
153  return false;
154  }
155 
156  static const bool value = test<T>(nullptr);
158 };
159 
165 template<typename T>
167 {
169  static const bool value =
175 };
176 
177 
178 } // namespace traits
179 
180 #endif // EOF
181 
template struct traits::is_random_access_char_sequence<T> exports a static const boolean member value...
Definition: traits.h:166
template struct traits::has_size_index_operator<T> exports a static const boolean member value that i...
Definition: traits.h:96
template struct traits::has_data_method<T> exports a static const boolean member value that is true i...
Definition: traits.h:120
template struct traits::has_size_method<T> exports a static const boolean member value that is true i...
Definition: traits.h:76
template struct traits::has_extend_method<T> exports a static const boolean member value that is true...
Definition: traits.h:143
template struct traits::has_value_type_of<T,V> exports a static const boolean member value that is tr...
Definition: traits.h:56