ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
container_operator.h
Go to the documentation of this file.
1#ifndef CONTAINER_OPERATOR_H
2#define CONTAINER_OPERATOR_H
3
4#include <cassert>
5#include <vector>
6#include <map>
7
8template< typename T>
9std::vector<T> operator + ( const std::vector<T> & x1, const std::vector<T> & x2 )
10{
11 assert(x1.size()==x2.size());
12 std::vector<T> x;
13 for(std::size_t i=0; i!=x1.size(); ++i )
14 x.push_back(x1[i]+x2[i]);
15 return x;
16}
17
18template< typename T>
19std::vector<T> operator - ( const std::vector<T> & x1, const std::vector<T> & x2 )
20{
21 assert(x1.size()==x2.size());
22 std::vector<T> x;
23 for(std::size_t i=0; i!=x1.size(); ++i )
24 x.push_back(x1[i]-x2[i]);
25 return x;
26}
27
28template< typename T1, typename T2 >
29std::map<T1,T2> operator + ( const std::map<T1,T2> & x1, const std::map<T1,T2> & x2 )
30{
31 assert(x1.size()==x2.size());
32 std::map<T1,T2> x;
33 for( const auto &x1i : x1 )
34 x.insert(std::make_pair( x1i.first, x1i.second + x2.at(x1i.first) ));
35 return x;
36}
37
38template< typename T1, typename T2 >
39std::map<T1,T2> operator - ( const std::map<T1,T2> & x1, const std::map<T1,T2> & x2 )
40{
41 assert(x1.size()==x2.size());
42 std::map<T1,T2> x;
43 for( const auto &x1i : x1 )
44 x.insert(std::make_pair( x1i.first, x1i.second - x2.at(x1i.first) ));
45 return x;
46}
47
48template< typename T1, typename T2 >
49std::vector<T2> operator * ( const T1 & x1, const std::vector<T2> & x2 )
50{
51 std::vector<T2> x;
52 for(std::size_t i=0; i!=x2.size(); ++i )
53 x.push_back(x1*x2[i]);
54 return x;
55}
56
57template< typename T1, typename T21, typename T22 >
58std::map<T21,T22> operator * ( const T1 & x1, const std::map<T21,T22> & x2 )
59{
60 std::map<T21,T22> x;
61 for( const auto & x2i : x2 )
62 x.insert(std::make_pair( x2i.first, x1*x2i.second ));
63 return x;
64}
65
66#endif // CONTAINER_OPERATOR_H
std::vector< T > operator-(const std::vector< T > &x1, const std::vector< T > &x2)
Definition container_operator.h:19
std::vector< T > operator+(const std::vector< T > &x1, const std::vector< T > &x2)
Definition container_operator.h:9
std::vector< T2 > operator*(const T1 &x1, const std::vector< T2 > &x2)
Definition container_operator.h:49