QMCPACK
container_traits.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2019 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Lab
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Lab
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_CONTAINER_TRAITS_H
14 #define QMCPLUSPLUS_CONTAINER_TRAITS_H
15 
16 #include <stdexcept>
17 #include <vector>
18 
19 namespace qmcplusplus
20 {
21 template<typename CT>
23 {
24  /// the data type of elements
25  using element_type = typename CT::value_type;
26 
27  /** resize container
28  * @param n the size of all the dimensions
29  * @param d the number of dimensions
30  */
31  template<typename I>
32  inline static void resize(CT& ref, I* n, int d)
33  {
34  throw std::runtime_error("Unknown container, resizing is not available!");
35  }
36 
37  /// get the current linear storage size of a container
38  inline static size_t getSize(const CT& ref) { return ref.size(); }
39 
40  /// get the linear storage pointer of a container
41  inline static auto getElementPtr(CT& ref) { return ref.data(); }
42 };
43 
44 // template specialization for std::vector
45 template<typename T, class ALLOC>
46 struct container_traits<std::vector<T, ALLOC>>
47 {
48  using element_type = T;
49  using CT = std::vector<T, ALLOC>;
50 
51  template<typename I>
52  inline static void resize(CT& ref, I* n, int d)
53  {
54  size_t nt = d > 0 ? 1 : 0;
55  for (int i = 0; i < d; ++i)
56  nt *= n[i];
57  ref.resize(nt);
58  }
59 
60  inline static size_t getSize(const CT& ref) { return ref.size(); }
61 
62  inline static auto getElementPtr(CT& ref) { return ref.data(); }
63 };
64 
65 } // namespace qmcplusplus
66 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
static size_t getSize(const CT &ref)
get the current linear storage size of a container
typename CT::value_type element_type
the data type of elements
static void resize(CT &ref, I *n, int d)
resize container
std::complex< double > I
static auto getElementPtr(CT &ref)
get the linear storage pointer of a container
QMCTraits::FullPrecRealType value_type