SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
type_traits.hpp
Go to the documentation of this file.
1 /*
2 Copyright© 2014 Akihiro Nishimura
3 
4 This software is released under the MIT License.
5 http://opensource.org/licenses/mit-license.php
6 */
7 
8 #ifndef _SIG_UTIL_TYPE_TRAITS_HPP
9 #define _SIG_UTIL_TYPE_TRAITS_HPP
10 
11 #include "../sigutil.hpp"
12 #include <iterator>
13 #include <type_traits>
14 
15 namespace sig
16 {
17 namespace impl
18 {
19 
20 #define CREATE_MEMBER_DETECTOR(X) \
21 template<typename T> class Detect_##X { \
22  struct Fallback { int X; }; \
23  struct Derived : T, Fallback { }; \
24  \
25  template<typename U, U> struct Check; \
26  \
27  typedef char ArrayOfOne[1]; \
28  typedef char ArrayOfTwo[2]; \
29  \
30  template<typename U> static ArrayOfOne & func(Check<int Fallback::*, &U::X> *); \
31  template<typename U> static ArrayOfTwo & func(...); \
32  public: \
33  typedef Detect_##X type; \
34  enum { value = sizeof(func<Derived>(0)) == 2 }; \
35 };
36 
37 template <class T>
38 struct is_const
39 {
40  static const bool value = std::is_const<typename std::remove_reference<T>::type>::value;
41 };
42 
43 template <class T>
44 struct identity
45 {
46  using type = T;
47 };
48 
49 template <class C>
51 {
53  static const bool value = Detect_iterator<C>::value;
54 };
55 
56 #if (SIG_MSVC_ENV && !(SIG_MSVC_VER < 120)) || (SIG_GCC_ENV) || (SIG_CLANG_ENV)
57 template <class C>
58 struct has_random_access_iter
59 {
60  template<class D, bool b> struct Sel{ using type = void; };
61  template<class D> struct Sel<D, true>{ using type = typename std::iterator_traits<typename D::iterator>::iterator_category; };
62 
63  template <class D>
64  struct impl_{
65  static const bool v = std::is_same<D, std::random_access_iterator_tag>::value;
66  };
67 
68  static const bool value = impl_<typename Sel<C, has_iterator<C>::value>::type>::v;
69 };
70 #endif
71 
72 //template <class T, class D = void> struct has_random_access_iter{ static const bool value = false; };
73 //template <class T> struct has_random_access_iter<T, decltype(std::declval<typename T::iterator>()[0], void())>{ static const bool value = true; };
74 
75 
76 } // impl
77 
78 } // sig
79 #endif
static const bool value
Definition: type_traits.hpp:40
#define CREATE_MEMBER_DETECTOR(X)
Definition: type_traits.hpp:20
static const bool value
Definition: type_traits.hpp:53
Definition: array.hpp:15