26 #ifndef TILEDARRAY_TILE_INTERFACE_ADD_H__INCLUDED
27 #define TILEDARRAY_TILE_INTERFACE_ADD_H__INCLUDED
29 #include "../tile_interface/cast.h"
30 #include "../tile_interface/permute.h"
31 #include "../type_traits.h"
42 template <
typename Left,
typename Right>
43 inline auto add(
const Left& left,
const Right& right)
44 -> decltype(left.add(right)) {
45 return left.add(right);
58 typename Left,
typename Right,
typename Scalar,
59 typename std::enable_if<detail::is_numeric_v<Scalar>>::type* =
nullptr>
60 inline auto add(
const Left& left,
const Right& right,
const Scalar factor) {
61 return left.add(right, factor);
73 typename Left,
typename Right,
typename Perm,
74 typename = std::enable_if_t<TiledArray::detail::is_permutation_v<Perm> &&
75 detail::has_member_function_add_anyreturn_v<
76 const Left,
const Right&,
const Perm&>>>
77 inline auto add(
const Left& left,
const Right& right,
const Perm& perm) {
78 return left.add(right, perm);
92 typename Left,
typename Right,
typename Scalar,
typename Perm,
93 typename std::enable_if<detail::is_numeric_v<Scalar> &&
94 detail::is_permutation_v<Perm>>::type* =
nullptr>
95 inline auto add(
const Left& left,
const Right& right,
const Scalar factor,
97 return left.add(right, factor, perm);
107 template <
typename Result,
typename Arg>
108 inline Result&
add_to(Result& result,
const Arg& arg) {
109 return result.add_to(arg);
122 typename Result,
typename Arg,
typename Scalar,
123 typename std::enable_if<detail::is_numeric_v<Scalar>>::type* =
nullptr>
124 inline Result&
add_to(Result& result,
const Arg& arg,
const Scalar factor) {
125 return result.add_to(arg, factor);
128 namespace tile_interface {
133 template <
typename... T>
136 template <
typename... T>
168 template <
typename Result,
typename Left,
typename Right,
169 typename Enabler =
void>
178 return add(left, right);
181 template <
typename Perm,
typename = std::enable_if_t<
182 TiledArray::detail::is_permutation_v<Perm>>>
184 const Perm& perm)
const {
186 return add(left, right, perm);
190 template <
typename Result,
typename Left,
typename Right>
191 class Add<Result, Left, Right,
192 typename std::enable_if<!(
193 std::is_same<Result, result_of_add_t<Left, Right>>::value &&
195 result_of_add_t<Left, Right, BipartitePermutation>>::
205 return cast(
add(left, right));
208 template <
typename Perm,
typename = std::enable_if_t<
209 TiledArray::detail::is_permutation_v<Perm>>>
211 const Perm& perm)
const {
214 return cast(
add(left, right, perm));
218 template <
typename Result,
typename Left,
typename Right,
typename Scalar,
219 typename Enabler =
void>
222 static_assert(TiledArray::detail::is_numeric_v<Scalar>,
223 "Cannot scale tiles by a non-scalar type");
233 return add(left, right, factor);
236 template <
typename Perm,
typename = std::enable_if_t<
237 TiledArray::detail::is_permutation_v<Perm>>>
239 const scalar_type factor,
const Perm& perm)
const {
241 return add(left, right, factor, perm);
245 template <
typename Result,
typename Left,
typename Right,
typename Scalar>
247 Result, Left, Right, Scalar,
248 typename std::enable_if<!(
249 std::is_same<Result, result_of_add_t<Left, Right, Scalar>>::value &&
250 std::is_same<Result, result_of_add_t<Left, Right, Scalar,
251 BipartitePermutation>>::value)>::
254 static_assert(TiledArray::detail::is_numeric_v<Scalar>,
255 "Cannot scale tiles by a non-scalar type");
266 return cast(
add(left, right, factor));
269 template <
typename Perm,
typename = std::enable_if_t<
270 TiledArray::detail::is_permutation_v<Perm>>>
272 const scalar_type factor,
const Perm& perm)
const {
275 return cast(
add(left, right, factor, perm));
279 template <
typename Result,
typename Left,
typename Right,
280 typename Enabler =
void>
289 return add_to(left, right);
293 template <
typename Result,
typename Left,
typename Right>
295 typename std::enable_if<!std::is_same<
296 Result, result_of_add_to_t<Left, Right>>::value>::type> {
310 template <
typename Result,
typename Left,
typename Right,
typename Scalar,
311 typename Enabler =
void>
314 static_assert(TiledArray::detail::is_numeric_v<Scalar>,
315 "Cannot scale tiles by a non-scalar type");
324 return add_to(left, right);
328 template <
typename Result,
typename Left,
typename Right,
typename Scalar>
330 Result, Left, Right, Scalar,
331 typename std::enable_if<!std::is_same<
332 Result, result_of_add_to_t<Left, Right, Scalar>>::value>::type> {
334 static_assert(TiledArray::detail::is_numeric_v<Scalar>,
335 "Cannot scale tiles by a non-scalar type");
360 template <
typename Result,
typename Left,
typename Right>
371 template <
typename Result,
typename Left,
typename Right,
typename Scalar>
382 template <
typename Result,
typename Left,
typename Right>
392 template <
typename Result,
typename Left,
typename Right,
typename Scalar>
399 #endif // TILEDARRAY_TILE_INTERFACE_ADD_H__INCLUDED