yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
Traits.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2017 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_TRAITS_H
7 #define YODA_TRAITS_H
8 
9 #include <type_traits>
10 
11 namespace YODA {
12 
13 
14  namespace SFINAE {
16  typedef char yes[1]; typedef char no[2];
17 
19  template <typename ...>
20  using void_t = void;
21  }
22 
23 
25  template <typename T, typename=void>
26  struct Derefable : std::false_type {};
27  //
28  template <typename T>
30 
31 
33  template <typename T, typename=AnalysisObject>
34  struct DerefableToAO : std::false_type {};
35  //
36  template <typename T>
37  struct DerefableToAO<T, typename std::conditional<std::is_base_of<AnalysisObject, typename std::decay< decltype(*std::declval<T>()) >::type>::value,
38  AnalysisObject, void>::type> : std::true_type {};
39  // The following would not be enough since it doesn't work with e.g. Histo1D*:
40  // struct DerefableToAO<T, typename std::decay< decltype(*std::declval<T>()) >::type > : std::true_type {};
41 
42 
43  // SFINAE struct to check for iterator concept at compile time
45  template<typename T>
46  struct Iterable {
47  template <typename C> static SFINAE::yes& test(typename C::iterator* c);
48  template <typename> static SFINAE::no& test(...);
49  static const bool value = sizeof(test<T>(0)) == sizeof(SFINAE::yes);
50  };
51 
52 
53  // SFINAE struct to check for const_iterator concept at compile time
55  template<typename T>
56  struct CIterable {
57  template <typename C> static SFINAE::yes& test(typename C::const_iterator* c);
58  template <typename> static SFINAE::no& test(...);
59  static const bool value = sizeof(test<T>(0)) == sizeof(SFINAE::yes);
60  };
61 
62 
63  // SFINAE struct to check for pushing concept at compile time
65  template<typename T,typename VAL>
66  struct Pushable {
67  template <typename SIG,SIG> struct has_sig;
68  template<typename C> static SFINAE::yes& test(has_sig<void (C::*) (const VAL&),&C::push_back>*);
69  template<typename C> static SFINAE::no& test(...);
70  static const bool value = sizeof(test<T>(0)) == sizeof(SFINAE::yes);
71  };
72 
73 
74 }
75 
76 #endif
SFINAE definition of dereferenceability trait, cf. Boost has_dereference.
Definition: Traits.h:26
void void_t
C++11 equivalent of C++17 std::void_t.
Definition: Traits.h:20
STL namespace.
char yes[1]
Definition: Traits.h:16
char no[2]
Definition: Traits.h:16
SFINAE struct to check for dereferencing to an AnalysisObject (reference) at compile time...
Definition: Traits.h:34