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 "../tile_interface/cast.h"
30 #include "../type_traits.h"
31 
32 namespace TiledArray {
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>
50  typename std::decay<decltype(clone(std::declval<T>()))>::type;
51 
53 
58 template <typename Arg, typename Enabler = void>
59 struct clone_trait {
60  typedef Arg type;
61 };
62 
64 
69 template <typename Arg>
70 struct clone_trait<Arg, typename std::enable_if<TiledArray::detail::is_type<
71  result_of_clone_t<Arg> >::value>::type> {
73 };
74 
75 // Internal tile clone operation
76 
81 template <typename Result, typename Arg, typename Enabler = void>
82 class Clone {
83  public:
84  typedef Result result_type;
85  typedef Arg argument_type;
86 
87  result_type operator()(const argument_type& arg) const {
88  using TiledArray::clone;
89  return clone(arg);
90  }
91 };
92 
93 // Internal tile clone and cast operation
94 
99 template <typename Result, typename Arg>
100 class Clone<Result, Arg,
101  typename std::enable_if<!std::is_same<
102  Result, typename clone_trait<Arg>::type>::value>::type>
103  : public TiledArray::Cast<Result, Arg> {};
104 
105 } // namespace tile_interface
106 
108 
115 template <typename Arg>
117 
119 
127 template <typename Result, typename Arg>
128 class Clone : public TiledArray::tile_interface::Clone<Result, Arg> {};
129 
130 } // namespace TiledArray
131 
132 #endif // TILEDARRAY_TILE_INTERFACE_CLONE_H__INCLUDED
Internal clone trait.
Definition: clone.h:59
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
Definition: clone.h:43
Clone trait.
Definition: clone.h:116
result_type operator()(const argument_type &arg) const
Definition: clone.h:87
Tile cast operation.
Definition: cast.h:168
Arg argument_type
Argument tile type.
Definition: clone.h:85
typename std::decay< decltype(clone(std::declval< T >()))>::type result_of_clone_t
Definition: clone.h:50
Result result_type
Result tile type.
Definition: clone.h:84
Create a deep copy of a tile.
Definition: clone.h:128