yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
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-2024 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_TRAITS_H
7#define YODA_TRAITS_H
8
10#include <type_traits>
11
12namespace YODA {
13
15 template <typename T, typename=void>
16 struct Derefable : std::false_type {};
17 //
18 template <typename T>
19 struct Derefable<T, std::void_t< decltype(*std::declval<T>())> > : std::true_type {};
20
21
23 template <typename T, typename=AnalysisObject>
24 struct DerefableToAO : std::false_type {};
25 //
26 template <typename T>
27 struct DerefableToAO<T, typename std::conditional<std::is_base_of<AnalysisObject,
28 typename std::decay< decltype(*std::declval<T>()) >::type>::value,
29 AnalysisObject, void>::type> : std::true_type {};
30 // The following would not be enough since it doesn't work with e.g. Histo1D*:
31 // struct DerefableToAO<T, typename std::decay< decltype(*std::declval<T>()) >::type > : std::true_type {};
32
33
34 // SFINAE struct to check for iterator concept at compile time
35 // Also works for C-style arrays.
36 template<typename T, typename = void>
37 struct Iterable : std::false_type { };
38 //
39 template<typename T>
40 struct Iterable<T, std::void_t<std::decay_t<decltype(std::begin(std::declval<const T&>()))>,
41 std::decay_t<decltype(std::end(std::declval<const T&>()))>>> : std::true_type { };
42
43 template<typename... T>
44 inline constexpr bool isIterable = std::conjunction<Iterable<T>...>::value;
45
46 // SFINAE struct to check for const_iterator concept at compile time
47 template<typename T, typename = void>
48 struct CIterable : std::false_type { };
49
50 template<typename T>
51 struct CIterable<T, std::void_t<decltype(std::declval<typename T::const_iterator>())>> : std::true_type { };
52
53 template<typename... T>
54 inline constexpr bool isCIterable = std::conjunction<CIterable<T>...>::value;
55
56 // SFINAE struct to check for pushing concept at compile time
57 template<typename T, typename VAL, typename = void>
58 struct Pushable : std::false_type { };
59 //
60 template<typename T, typename VAL>
61 struct Pushable<T, VAL, std::void_t<decltype(std::declval<T>().push_back( std::declval<VAL>() ))>>
62 : std::true_type { };
63
64 // SFINAE struct to check for concept of fill dimension at compile time
65 template<typename T, typename = void>
66 struct hasFillDim : std::false_type { };
67 //
68 template<typename T>
69 struct hasFillDim<T, std::void_t<decltype(typename T::FillDim{})>> : std::true_type { };
70
71}
72
73#endif
Anonymous namespace to limit visibility.
constexpr bool isIterable
Definition Traits.h:44
constexpr bool isCIterable
Definition Traits.h:54
SFINAE struct to check for dereferencing to an AnalysisObject (reference) at compile time.
Definition Traits.h:24
SFINAE definition of dereferenceability trait, cf. Boost has_dereference.
Definition Traits.h:16