piranha  0.10
is_key.hpp
1 /* Copyright 2009-2017 Francesco Biscani (bluescarni@gmail.com)
2 
3 This file is part of the Piranha library.
4 
5 The Piranha library is free software; you can redistribute it and/or modify
6 it under the terms of either:
7 
8  * the GNU Lesser General Public License as published by the Free
9  Software Foundation; either version 3 of the License, or (at your
10  option) any later version.
11 
12 or
13 
14  * the GNU General Public License as published by the Free Software
15  Foundation; either version 3 of the License, or (at your option) any
16  later version.
17 
18 or both in parallel, as here.
19 
20 The Piranha library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24 
25 You should have received copies of the GNU General Public License and the
26 GNU Lesser General Public License along with the Piranha library. If not,
27 see https://www.gnu.org/licenses/. */
28 
29 #ifndef PIRANHA_IS_KEY_HPP
30 #define PIRANHA_IS_KEY_HPP
31 
32 #include <iostream>
33 #include <type_traits>
34 #include <utility>
35 #include <vector>
36 
37 #include <piranha/symbol_utils.hpp>
38 #include <piranha/type_traits.hpp>
39 
40 namespace piranha
41 {
42 
44 
61 // \todo requirements on vector-of-symbols-constructed key: must it be unitary? (seems like it, look at
62 // polynomial ctors from symbol) -> note that both these two checks have to go in the runtime requirements of key
63 // when they get documented.
64 template <typename T>
65 class is_key
66 {
67  template <typename U>
68  using is_compatible_t = decltype(std::declval<const U &>().is_compatible(std::declval<symbol_fset const &>()));
69  template <typename U>
70  using is_zero_t = decltype(std::declval<const U &>().is_zero(std::declval<symbol_fset const &>()));
71  template <typename U>
72  using merge_symbols_t = decltype(std::declval<const U &>().merge_symbols(
73  std::declval<const symbol_idx_fmap<symbol_fset> &>(), std::declval<symbol_fset const &>()));
74  template <typename U>
75  using is_unitary_t = decltype(std::declval<const U &>().is_unitary(std::declval<symbol_fset const &>()));
76  template <typename U>
77  using print_t = decltype(
78  std::declval<const U &>().print(std::declval<std::ostream &>(), std::declval<symbol_fset const &>()));
79  template <typename U>
80  using print_tex_t = decltype(
81  std::declval<const U &>().print_tex(std::declval<std::ostream &>(), std::declval<symbol_fset const &>()));
82  template <typename U>
83  using trim_identify_t = decltype(std::declval<const U &>().trim_identify(std::declval<std::vector<char> &>(),
84  std::declval<symbol_fset const &>()));
85  template <typename U>
86  using trim_t = decltype(
87  std::declval<const U &>().trim(std::declval<const std::vector<char> &>(), std::declval<symbol_fset const &>()));
88  template <typename U>
89  using check_methods_t = std::integral_constant<
90  bool,
91  conjunction<std::is_same<detected_t<is_compatible_t, U>, bool>, std::is_same<detected_t<is_zero_t, U>, bool>,
92  std::is_same<detected_t<merge_symbols_t, U>, U>, std::is_same<detected_t<is_unitary_t, U>, bool>,
93  std::is_same<detected_t<print_t, U>, void>, std::is_same<detected_t<print_tex_t, U>, void>,
94  std::is_same<detected_t<trim_identify_t, U>, void>, std::is_same<detected_t<trim_t, U>, U>>::value>;
95  template <typename U, typename = void>
96  struct is_key_impl {
97  static const bool value = false;
98  };
99  template <typename U>
100  struct is_key_impl<U, enable_if_t<check_methods_t<U>::value>> {
101  static const bool value
102  = conjunction<is_container_element<U>, std::is_constructible<U, const symbol_fset &>,
104  && noexcept(std::declval<const U &>().is_compatible(std::declval<const symbol_fset &>()))
105  && noexcept(std::declval<const U &>().is_zero(std::declval<const symbol_fset &>()));
106  };
107  static const bool implementation_defined = is_key_impl<T>::value;
108 
109 public:
111  static const bool value = implementation_defined;
112 };
113 
114 template <typename T>
115 const bool is_key<T>::value;
116 }
117 
118 #endif
Equality-comparable type trait.
Key type concept check.
Definition: is_key.hpp:65
Hashable type trait.
boost::container::flat_map< symbol_idx, T > symbol_idx_fmap
Flat map of symbol indices.
Root piranha namespace.
Definition: array_key.hpp:52
Type traits.
static const bool value
Value of the type trait.
Definition: is_key.hpp:111