OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ForeachZip.h
Go to the documentation of this file.
1 
9 #ifndef _OPENCOG_FOREACH_ZIP_H
10 #define _OPENCOG_FOREACH_ZIP_H
11 
13 
14 namespace opencog
15 {
29 template<class T>
30 inline bool foreach_atom_pair(const std::vector<Handle> &va,
31  const std::vector<Handle> &vb,
32  bool (T::*cb)(const Handle&, const Handle&), T *data)
33 {
34  size_t vasz = va.size();
35  size_t vbsz = vb.size();
36  size_t minsz = std::min(vasz, vbsz);
37 
38  for (size_t i = 0; i < minsz; i++) {
39  bool rc = (data->*cb)(va[i], vb[i]);
40  if (not rc) return false;
41  }
42 
43  for (size_t i = vasz; i < vbsz; i++) {
44  bool rc = (data->*cb)(Handle::UNDEFINED, vb[i]);
45  if (not rc) return false;
46  }
47  for (size_t i = vbsz; i < vasz; i++) {
48  bool rc = (data->*cb)(va[i], Handle::UNDEFINED);
49  if (not rc) return false;
50  }
51  return true;
52 }
53 
55 } // namespace opencog
56 
57 #endif // _OPENCOG_FOREACH_ZIP_H
static const Handle UNDEFINED
Definition: Handle.h:77
bool foreach_atom_pair(const std::vector< Handle > &va, const std::vector< Handle > &vb, bool(T::*cb)(const Handle &, const Handle &), T *data)
Definition: ForeachZip.h:30