vector.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2020 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  * Eduard Valeyev
19  * Department of Chemistry, Virginia Tech
20  *
21  * util/vector.h
22  * March 24, 2020
23  *
24  */
25 
26 #ifndef TILEDARRAY_UTIL_VECTOR_H
27 #define TILEDARRAY_UTIL_VECTOR_H
28 
29 #include <boost/container/small_vector.hpp>
30 #include <vector>
31 #include "TiledArray/config.h"
32 
33 #include <TiledArray/utility.h>
34 #include <madness/world/archive.h>
35 
36 namespace TiledArray {
37 
38 namespace container {
39 
40 template <typename T>
41 using vector = std::vector<T>;
42 template <typename T, std::size_t N = TA_MAX_SOO_RANK_METADATA>
43 using svector = boost::container::small_vector<T, N>;
44 
45 template <typename Range>
46 std::enable_if_t<detail::is_integral_range_v<Range> &&
47  detail::is_sized_range_v<Range>,
49 iv(Range&& rng) {
50  svector<detail::value_t<Range>> result(std::size(rng));
51  long count = 0;
52  for (auto&& v : rng) {
53  result[count] = v;
54  ++count;
55  }
56  return result;
57 }
58 
59 template <typename Int, typename = std::enable_if_t<std::is_integral_v<Int>>>
60 svector<Int> iv(std::initializer_list<Int> list) {
61  return svector<Int>(data(list), data(list) + size(list));
62 }
63 
64 namespace detail {
65 template <typename Vec, typename T, typename... Ts>
66 void iv_assign(Vec& d, size_t i, T v, Ts... vrest) {
67  d[i] = v;
68  if constexpr (sizeof...(Ts) > 0) {
69  iv_assign(d, i + 1, vrest...);
70  }
71 }
72 } // namespace detail
73 
74 template <typename Int, typename... Ints,
75  typename = std::enable_if_t<std::is_integral_v<Int> &&
76  (std::is_integral_v<Ints> && ...)>>
77 constexpr auto iv(Int i0, Ints... rest) {
78  constexpr const auto sz = sizeof...(Ints) + 1;
79  svector<std::common_type_t<Int, Ints...>, sz> result(sz);
80  detail::iv_assign(result, 0, i0, rest...);
81  return result;
82 }
83 
84 } // namespace container
85 } // namespace TiledArray
86 
87 namespace TiledArray {
88 
90 template <typename T, typename A>
91 inline std::ostream& operator<<(std::ostream& os,
92  const std::vector<T, A>& vec) {
94  return os;
95 }
96 
97 } // namespace TiledArray
98 
99 namespace boost {
100 namespace container {
101 
103 template <typename T, std::size_t N>
104 inline std::ostream& operator<<(
105  std::ostream& os, const boost::container::small_vector<T, N>& vec) {
107  return os;
108 }
109 
110 } // namespace container
111 } // namespace boost
112 
113 #endif // TILEDARRAY_UTIL_VECTOR_H
void iv_assign(Vec &d, size_t i, T v, Ts... vrest)
Definition: vector.h:66
boost::container::small_vector< T, N > svector
Definition: vector.h:43
std::enable_if_t< detail::is_integral_range_v< Range > &&detail::is_sized_range_v< Range >, svector< detail::value_t< Range > > > iv(Range &&rng)
Definition: vector.h:49
std::ostream & operator<<(std::ostream &os, const boost::container::small_vector< T, N > &vec)
Vector output stream operator.
Definition: vector.h:104
Definition: eigen.h:138
std::ostream & operator<<(std::ostream &os, const DistArray< Tile, Policy > &a)
Add the tensor to an output stream.
Definition: dist_array.h:1602
void print_array(std::ostream &out, const A &a, const std::size_t n)
Print the content of an array like object.
Definition: utility.h:48
std::vector< T > vector
Definition: vector.h:41
A (hyperrectangular) interval on , space of integer -indices.
Definition: range.h:46