TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
vector.hpp
Go to the documentation of this file.
1// Copyright (c) 2019-2024 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include "../clef.hpp"
25
26#include <utility>
27#include <vector>
28
29namespace nda::clef {
30
36 namespace detail {
37
38 // Helper function to auto assign to a std::vector object.
39 template <typename T, typename RHS>
40 void clef_auto_assign_std_vector_impl(T &x, RHS &&rhs) {
41 x = std::forward<RHS>(rhs);
42 }
43
44 // Helper function to auto assign to a std::vector object.
45 template <typename Expr, int... Is, typename T>
46 void clef_auto_assign_std_vector_impl(T &x, make_fun_impl<Expr, Is...> &&rhs) { // NOLINT (why rvalue reference?)
47 clef_auto_assign_subscript(x, std::forward<make_fun_impl<Expr, Is...>>(rhs));
48 }
49
50 } // namespace detail
51
60 template <typename T, typename F>
61 void clef_auto_assign_subscript(std::vector<T> &v, F f) {
62 for (size_t i = 0; i < v.size(); ++i) detail::clef_auto_assign_std_vector_impl(v[i], f(i));
63 }
64
67} // namespace nda::clef
Includes all relevant headers for the core clef library.
void clef_auto_assign_subscript(std::vector< T > &v, F f)
Overload of clef_auto_assign_subscript function for std::vector.
Definition vector.hpp:61