blitzdg
an open-source project aiming to implement parallel discontinuous Galerkin (dg) solvers for common partial differential equations systems using blitz++ for array and tensor manipulations and MPI for distributed parallelism.
equalscontainerconstraint.h
1 
2 // Copyright Joakim Karlsson & Kim Gräsman 2010-2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef IGLOO_EQUALSCONTAINERCONSTRAINT_H
8 #define IGLOO_EQUALSCONTAINERCONSTRAINT_H
9 
10 namespace snowhouse {
11 
12  namespace constraint_internal {
13  template<typename T>
14  inline bool default_comparer(const T& lhs, const T& rhs)
15  {
16  return lhs == rhs;
17  }
18  }
19 
20  template< typename ExpectedType, typename BinaryPredicate>
21  struct EqualsContainerConstraint : Expression< EqualsContainerConstraint<ExpectedType, BinaryPredicate> >
22  {
23  EqualsContainerConstraint(const ExpectedType& expected, const BinaryPredicate predicate)
24  : expected_(expected), predicate_(predicate)
25  {}
26 
27  template<typename ActualType>
28  bool operator()(const ActualType& actual) const
29  {
30  typename ActualType::const_iterator actual_it;
31  typename ExpectedType::const_iterator expected_it;
32 
33  for(actual_it = actual.begin(), expected_it = expected_.begin(); actual_it != actual.end() && expected_it != expected_.end(); actual_it++, expected_it++)
34  {
35  if(!predicate_(*actual_it, *expected_it))
36  {
37  return false;
38  }
39  }
40 
41  return actual.size() == expected_.size();
42  }
43 
44  const ExpectedType expected_;
45  const BinaryPredicate predicate_;
46  };
47 
48  template< typename ExpectedType>
50  {
52  }
53 
54  template< typename ExpectedType, typename BinaryPredicate >
55  inline EqualsContainerConstraint<ExpectedType, BinaryPredicate> EqualsContainer(const ExpectedType& expected, const BinaryPredicate predicate)
56  {
58  }
59 
60  template< typename ExpectedType, typename BinaryPredicate >
61  struct Stringizer< EqualsContainerConstraint<ExpectedType, BinaryPredicate> >
62  {
63  static std::string ToString(const EqualsContainerConstraint<ExpectedType, BinaryPredicate>& constraint)
64  {
65  std::ostringstream builder;
66  builder << snowhouse::Stringize(constraint.expected_);
67  return builder.str();
68  }
69  };
70 }
71 
72 #endif
Definition: assert.h:13
Definition: stringize.h:71
Definition: equalscontainerconstraint.h:21
Definition: expression.h:17