20 #ifndef TILEDARRAY_EXPRESSIONS_VARIABLE_LIST_H__INCLUDED 21 #define TILEDARRAY_EXPRESSIONS_VARIABLE_LIST_H__INCLUDED 29 namespace expressions {
32 VariableList
operator *(const ::TiledArray::Permutation&,
const VariableList&);
33 void swap(VariableList&, VariableList&);
63 template<
typename InIter1,
typename InIter2>
64 void find_common(InIter1 first1,
const InIter1 last1, InIter2 first2,
const InIter2 last2,
65 std::pair<InIter1, InIter1>& common1, std::pair<InIter2, InIter2>& common2)
67 common1.first = last1;
68 common1.second = last1;
69 common2.first = last2;
70 common2.second = last2;
73 for(; first1 != last1; ++first1) {
74 common2.first = std::find(first2, last2, *first1);
75 if(common2.first != last2)
78 common1.first = first1;
79 first2 = common2.first;
82 while((first1 != last1) && (first2 != last2)) {
83 if(*first1 != *first2)
88 common1.second = first1;
89 common2.second = first2;
92 template <
typename VarLeft,
typename VarRight>
95 std::vector<size_t> a(l.size());
96 typename VarRight::const_iterator rit = r.begin();
97 for(
auto it = a.begin(); it != a.end(); ++it) {
98 typename VarLeft::const_iterator lit = std::find(l.begin(), l.end(), *rit++);
100 *it = std::distance(l.begin(), lit);
124 template<
typename InIter>
127 "VariableList constructor requires an input iterator");
130 for(; first != last; ++first)
131 vars_.push_back(trim_spaces_(first->begin(), first->end()));
161 const std::string&
at(
const std::size_t n)
const {
return vars_.at(n); }
164 const std::string&
operator [](
const std::size_t n)
const {
return vars_[n]; }
167 unsigned int dim()
const {
return vars_.size(); }
170 unsigned int size()
const {
return vars_.size(); }
172 const std::vector<std::string>&
data()
const {
return vars_; }
176 std::vector<std::string>::const_iterator it = vars_.begin();
177 if(it == vars_.end())
180 for(result = *it++; it != vars_.end(); ++it) {
198 template <
typename V>
208 if(vars_.size() != other.vars_.size())
213 for(; other_it != other.
end(); ++other_it)
216 if(other_it == other.
end())
227 void init_(
const std::string& vars) {
228 std::string::const_iterator start = vars.begin();
229 std::string::const_iterator finish = vars.begin();
230 for(; finish != vars.end(); ++finish) {
232 vars_.push_back(trim_spaces_(start, finish));
236 vars_.push_back(trim_spaces_(start, finish));
238 TA_ASSERT( (unique_(vars_.begin(), vars_.end())));
243 static std::string trim_spaces_(std::string::const_iterator first, std::string::const_iterator last) {
245 std::string result =
"";
246 for(;first != last; ++first) {
248 if(*first !=
' ' && *first !=
'\0')
249 result.append(1, *first);
258 template<
typename InIter>
259 bool unique_(InIter first, InIter last)
const {
260 for(; first != last; ++first) {
262 for(++it2; it2 != last; ++it2)
263 if(first->compare(*it2) == 0)
270 static bool valid_char_(
char c) {
271 return (c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') ||
272 (c >=
'0' && c <=
'9') || (c ==
' ') || (c ==
',') || (c ==
'\0') ||
273 (c ==
'\'') || (c ==
'_');
278 std::vector<std::string> vars_;
300 result.vars_ = p * v.vars_;
309 std::size_t n = v.
dim() - 1;
310 for(d = 0; d < n; ++d) {
322 #endif // TILEDARRAY_EXPRESSIONS_VARIABLE_LIST_H__INCLUDED void swap(VariableList &, VariableList &)
Exchange the content of the two variable lists.
ExprTraceTarget operator<<(std::ostream &os, const TsrExpr< A, Alias > &tsr)
Expression trace factory function.
VariableList(const std::string &vars)
constructs a variable lists
void find_common(InIter1 first1, const InIter1 last1, InIter2 first2, const InIter2 last2, std::pair< InIter1, InIter1 > &common1, std::pair< InIter2, InIter2 > &common2)
Finds the range of common elements for two sets of iterators.
Permutation permutation(const V &other) const
Generate permutation relationship for variable lists.
VariableList(InIter first, InIter last)
VariableList & operator*=(const Permutation &p)
bool operator!=(const VariableList &v0, const VariableList &v1)
std::string string() const
std::enable_if< TiledArray::detail::is_numeric< Scalar >::value, ScalAddExpr< Left, Right, Scalar > >::type operator*(const AddExpr< Left, Right > &expr, const Scalar &factor)
Scaled-addition expression factor.
const std::string & operator[](const std::size_t n) const
Returns the n-th string in the variable list.
const std::vector< std::string > & data() const
unsigned int dim() const
Returns the number of strings in the variable list.
index_type dim() const
Domain size accessor.
Variable list manages a list variable strings.
std::vector< std::string >::const_iterator const_iterator
Permutation var_perm(const VarLeft &l, const VarRight &r)
friend VariableList operator*(const ::TiledArray::Permutation &, const VariableList &)
bool is_permutation(const VariableList &other) const
Check that this variable list is a permutation of other.
Permutation of a sequence of objects indexed by base-0 indices.
const_iterator end() const
Returns an iterator to the end of the variable list.
void swap(VariableList &other)
VariableList(const VariableList &other)
const std::string & at(const std::size_t n) const
Returns the n-th string in the variable list.
VariableList()
Constructs an empty variable list.
bool operator==(const VariableList &v0, const VariableList &v1)
const_iterator begin() const
Returns an iterator to the first variable.
VariableList & operator=(const VariableList &other)
unsigned int size() const
Returns the number of strings in the variable list.