HILA
Loading...
Searching...
No Matches
has_unary_minus.h
1#ifndef HAS_UNARY_MINUS_H
2#define HAS_UNARY_MINUS_H
3
4#include <type_traits>
5
6/**
7 *@details Namespace `hila` contains most of `class templates` and `function templates`, which are
8 * necessary to run lattice filed simulations on distributed memory system as well as
9 * on GPU nodes concurrently.
10 */
11namespace hila {
12
13/**
14 *@brief Conditionally reture `bool` type `false` if type `T` does't have unary `-` operator
15 *
16 *@details If the type T does not implement `-T` (unary `-`) operator, i.e.
17 *\code{.cpp}
18 * T T::operator-() const { ... }
19 *\endcode,
20 *`has_unary_minus::value` is `false`. This is needed for antiperiodic boundary conditions
21 * @note `value` is false for `unsigned` type, whereas c++ allows `-unsigned`
22 */
23template <typename T, typename A = void>
25 public:
26 static constexpr bool value = false;
27};
28
29template <typename T>
30class has_unary_minus<
31 T, typename std::enable_if_t<!std::is_unsigned<hila::arithmetic_type<T>>::value &&
32 hila::is_assignable<T &, decltype(-std::declval<T>())>::value>> {
33 public:
34 static constexpr bool value = true;
35};
36
37/**
38 *@brief hila::has_assign_zero<T>::value returns true if '= 0 is defined for T
39 *
40 */
41template <typename T, typename A = void>
43 public:
44 static constexpr bool value = false;
45};
46
47template <typename T>
48class has_assign_zero<T, typename std::enable_if_t<hila::is_arithmetic<T>::value ||
49 hila::is_assignable<T &, int>::value ||
50 hila::is_assignable<T &, std::nullptr_t>::value>> {
51 public:
52 static constexpr bool value = true;
53};
54
55
56} // namespace hila
57
58#endif
hila::has_assign_zero<T>::value returns true if '= 0 is defined for T
Conditionally reture bool type false if type T does't have unary - operator.
Implement hila::swap for gauge fields.
Definition array.h:981