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
29/**
30 *@brief Conditionally reture `bool` type `true` if type `T` has unary `-` operator
31 *
32 *@details If the type T has been implemented `-T` (unary `-`) operator, i.e.
33 *\code{.cpp}
34 * T T::operator-() const { ... }
35 *\endcode,
36 *`has_unary_minus::value` is `true`. This is needed for antiperiodic boundary conditions
37 * @note `value` is false for `unsigned` type, whereas c++ allows `-unsigned`
38 */
39template <typename T>
41 T, typename std::enable_if_t<!std::is_unsigned<hila::arithmetic_type<T>>::value &&
42 hila::is_assignable<T &, decltype(-std::declval<T>())>::value>> {
43 public:
44 static constexpr bool value = true;
45};
46
47/**
48 *@brief hila::has_assign_zero<T>::value returns true if '= 0 is defined for T
49 *
50 */
51template <typename T, typename A = void>
53 public:
54 static constexpr bool value = false;
55};
56
57template <typename T>
58class has_assign_zero<T, typename std::enable_if_t<hila::is_arithmetic<T>::value ||
59 hila::is_assignable<T &, int>::value ||
60 hila::is_assignable<T &, std::nullptr_t>::value>> {
61 public:
62 static constexpr bool value = true;
63};
64
65
66} // namespace hila
67
68#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