TiledArray  0.7.0
clone.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  * clone.h
22  * Jan 10, 2016
23  *
24  */
25 
26 #ifndef TILEDARRAY_TILE_INTERFACE_CLONE_H__INCLUDED
27 #define TILEDARRAY_TILE_INTERFACE_CLONE_H__INCLUDED
28 
29 #include "../type_traits.h"
30 
31 namespace TiledArray {
32 
33 
35 
39  template <typename Arg>
40  inline auto clone(const Arg& arg) {
41  return arg.clone();
42  }
43 
44  namespace tile_interface {
45 
46  using TiledArray::clone;
47 
48  template <typename T>
49  using result_of_clone_t = typename std::decay<decltype(clone(std::declval<T>()))>::type;
50 
52 
57  template <typename Arg, typename Enabler = void>
58  struct clone_trait {
59  typedef Arg type;
60  };
61 
63 
68  template <typename Arg>
69  struct clone_trait<Arg,
70  typename std::enable_if<
71  TiledArray::detail::is_type<result_of_clone_t<Arg> >::value
72  >::type>
73  {
75  };
76 
77 
78  // Internal tile clone operation
79 
84  template <typename Result, typename Arg, typename Enabler = void>
85  class Clone {
86  public:
87 
88  typedef Result result_type;
89  typedef Arg argument_type;
90 
91  result_type operator()(const argument_type& arg) const {
92  using TiledArray::clone;
93  return clone(arg);
94  }
95  };
96 
97  // Internal tile clone and cast operation
98 
103  template <typename Result, typename Arg>
104  class Clone<Result, Arg,
105  typename std::enable_if<
106  ! std::is_same<Result, typename clone_trait<Arg>::type >::value
107  >::type> :
108  public TiledArray::Cast<Result, Arg>
109  { };
110 
111  } // namespace tile_interface
112 
113 
115 
122  template <typename Arg>
123  struct clone_trait :
125  { };
126 
127 
129 
137  template <typename Result, typename Arg>
138  class Clone : public TiledArray::tile_interface::Clone<Result, Arg> { };
139 
140 
141 } // namespace TiledArray
142 
143 #endif // TILEDARRAY_TILE_INTERFACE_CLONE_H__INCLUDED
Tile cast operation.
Definition: cast.h:34
Clone trait.
Definition: clone.h:123
Internal clone trait.
Definition: clone.h:58
STL namespace.
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
Definition: clone.h:43
typename std::decay< decltype(clone(std::declval< T >()))>::type result_of_clone_t
Definition: clone.h:49
Result result_type
Result tile type.
Definition: clone.h:88
result_type operator()(const argument_type &arg) const
Definition: clone.h:91
Arg argument_type
Argument tile type.
Definition: clone.h:89
Create a deep copy of a tile.
Definition: clone.h:138