TiledArray  0.7.0
shift.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2016 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Justus Calvin
19  * Department of Chemistry, Virginia Tech
20  *
21  * shift.h
22  * Jan 10, 2016
23  *
24  */
25 
26 #ifndef TILEDARRAY_TILE_INTERFACE_SHIFT_H__INCLUDED
27 #define TILEDARRAY_TILE_INTERFACE_SHIFT_H__INCLUDED
28 
29 #include "../type_traits.h"
30 #include "cast.h"
31 
32 namespace TiledArray {
33 
35 
41  template <typename Arg, typename Index>
42  inline auto shift(const Arg& arg, const Index& range_shift)
43  { return arg.shift(range_shift); }
44 
45 
47 
53  template <typename Arg, typename Index>
54  inline auto shift_to(Arg& arg, const Index& range_shift)
55  { return arg.shift_to(range_shift); }
56 
57 
58  namespace tile_interface {
59 
60  using TiledArray::shift;
62 
63  template <typename T>
64  using result_of_shift_t = typename std::decay<
65  decltype(shift(std::declval<T>(),
66  std::declval<std::vector<long> >()))>::type;
67 
68  template <typename T>
69  using result_of_shift_to_t = typename std::decay<
70  decltype(shift_to(std::declval<T>(),
71  std::declval<std::vector<long> >()))>::type;
72 
73  template <typename Result, typename Arg, typename Enabler = void>
74  class Shift {
75  public:
76 
77  typedef Result result_type;
78  typedef Arg argument_type;
79 
80  template <typename Index>
82  const Index& range_shift) const
83  { return shift(arg, range_shift); }
84  };
85 
86  template <typename Result, typename Arg>
87  class Shift<Result, Arg,
88  typename std::enable_if<
89  ! std::is_same<Result, result_of_shift_t<Arg> >::value
90  >::type> :
91  public TiledArray::Cast<Result, result_of_shift_t<Arg> >
92  {
93  private:
95  public:
96 
97  typedef Result result_type;
98  typedef Arg argument_type;
99 
100  template <typename Index>
102  const Index& range_shift) const
103  { return Cast_::operator()(shift(arg, range_shift)); }
104 
105  };
106 
107  template <typename Result, typename Arg, typename Enabler = void>
108  class ShiftTo {
109  public:
110 
111  typedef Result result_type;
112  typedef Arg argument_type;
113 
114  template <typename Index>
116  const Index& range_shift) const
117  { return shift_to(arg, range_shift); }
118  };
119 
120 
121  template <typename Result, typename Arg>
122  class ShiftTo<Result, Arg,
123  typename std::enable_if<
124  ! std::is_same<Result, result_of_shift_to_t<Arg> >::value
125  >::type> :
126  public TiledArray::Cast<Result, result_of_shift_to_t<Arg> >
127  {
128  private:
130  public:
131 
132  typedef Result result_type;
133  typedef Arg argument_type;
134 
135  template <typename Index>
137  const Index& range_shift) const
138  { return Cast_::operator()(shift_to(arg, range_shift)); }
139 
140  };
141 
142 
143  template <typename Arg, typename Enabler = void>
144  struct shift_trait {
145  typedef Arg type;
146  };
147 
148 
149  template <typename Arg>
150  struct shift_trait<Arg,
151  typename std::enable_if<
152  TiledArray::detail::is_type<result_of_shift_t<Arg> >::value
153  >::type>
154  {
156  };
157 
158  } // namespace tile_interface
159 
160 
162 
167  template <typename Result, typename Arg>
168  class Shift : public TiledArray::tile_interface::Shift<Result, Arg> { };
169 
170 
172 
177  template <typename Result, typename Arg>
178  class ShiftTo : public TiledArray::tile_interface::ShiftTo<Result, Arg> { };
179 
180 
181 } // namespace TiledArray
182 
183 #endif // TILEDARRAY_TILE_INTERFACE_SHIFT_H__INCLUDED
Shift the range of tile in place.
Definition: shift.h:178
detail::ShiftWrapper< T > shift(T &tensor)
Shift a tensor from one range to another.
Tile cast operation.
Definition: cast.h:34
Shift the range of tile.
Definition: shift.h:168
result_type operator()(const argument_type &arg, const Index &range_shift) const
Definition: shift.h:81
STL namespace.
typename std::decay< decltype(shift(std::declval< T >(), std::declval< std::vector< long > >()))>::type result_of_shift_t
Definition: shift.h:66
Result result_type
Result tile type.
Definition: shift.h:111
result_type operator()(argument_type &arg, const Index &range_shift) const
Definition: shift.h:115
Result result_type
Result tile type.
Definition: shift.h:77
Arg argument_type
Argument tile type.
Definition: shift.h:78
Arg argument_type
Argument tile type.
Definition: shift.h:112
typename std::decay< decltype(shift_to(std::declval< T >(), std::declval< std::vector< long > >()))>::type result_of_shift_to_t
Definition: shift.h:71
Tile< Arg > & shift_to(Tile< Arg > &arg, const Index &range_shift)
Shift the range of arg in place.
Definition: tile.h:346