ALPSCore reference
view.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #ifndef ALPSCORE_GF_VIEW_H
8 #define ALPSCORE_GF_VIEW_H
9 
10 
11 #include "data_storage.hpp"
12 
13 namespace alps {
14  namespace numerics {
15  namespace detail {
16 
22  template<typename T>
23  class view {
24  private:
26  T* data_;
28  size_t size_;
29  public:
34  view(typename std::remove_cv<T>::type * data, size_t size) : data_(data), size_(size){}
35  view(const T* data, size_t size) : data_(const_cast<T*>(data)), size_(size){}
39  view(data_storage<T>&storage) : data_(storage.data()), size_(storage.size()) {}
41  view(const view & view) : data_(view.data_), size_(view.size_) {}
43  view(view && view) : data_(view.data_), size_(view.size_) {}
44 
46  view<T>& operator=(const view<T> & rhs) {
47  assert(size_ == rhs.size_);
48  std::copy(rhs.data_, rhs.data_+rhs.size_, data_);
49  return (*this);
50  }
51 
53  view<T> operator=(view<T> && rhs) {
54  assert(size_ == rhs.size_);
55  std::copy(rhs.data_, rhs.data_+rhs.size_, data_);
56  return (*this);
57  }
58 
60  inline T& data(size_t i) {return data_[i];};
62  inline const T& data(size_t i) const {return data_[i];};
64  size_t size() const {return size_;}
66  inline T* data() {return data_;};
68  inline const T* data() const {return data_;};
69  };
70  }
71  }
72 }
73 
74 #endif //ALPSCORE_GF_VIEW_H
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
Definition: size.hpp:20