[Rivet] Updated Cuts system prototype/demo

David Grellscheid david.grellscheid at durham.ac.uk
Fri May 3 17:15:28 BST 2013


Hi Andy,

What I was thinking of only works if you're allowed to evaluate the 
template expression on assignment (as in vecA = vecB + vecC + vecD). 
Here, we need to pass the unevaluated expressions around instead.

But isn't that what the base class is for? Turn all the operator members 
into const references and then all your 'auto' can become "const Cut &". 
No template mess needed, and forgetting the '&' anywhere causes a 
compiler error beause of the abstract base class.

Diff attached...

   David



On 03/05/2013 16:22, David Grellscheid wrote:
> Hi Andy,
>
> I like it, it's really neat now! I have the feeling that something can
> still be condensed a bit more, but I'll have to play with it. The
> Softsusy code successfully hides the template stuff completely away from
> the end users, so I must have had a way of achieving that 10 years ago
> without C++11 :-D
>
> I'll copy the pastebin and send you a diff if I get it sorted.
>
> See you,
>
>    David
> _______________________________________________
> Rivet mailing list
> Rivet at projects.hepforge.org
> http://www.hepforge.org/lists/listinfo/rivet
-------------- next part --------------
diff -r b75b07fd5a57 cuts.cc
--- a/cuts.cc	Fri May 03 17:10:54 2013 +0100
+++ b/cuts.cc	Fri May 03 17:13:11 2013 +0100
@@ -36,23 +36,23 @@
 struct CutsOr : public Cut {
   CutsOr(const CUT1& c1, const CUT2& c2) : cut1(c1), cut2(c2) { }
   bool cut(int n) const { return cut1.cut(n) || cut2.cut(n); }
-  CUT1 cut1;
-  CUT2 cut2;
+  const CUT1 & cut1;
+  const CUT2 & cut2;
   BOOST_STATIC_ASSERT((boost::is_base_of<Cut, CUT1>::value && boost::is_base_of<Cut, CUT2>::value));
 };
 template <typename CUT1, typename CUT2>
 struct CutsAnd : public Cut {
   CutsAnd(const CUT1& c1, const CUT2& c2) : cut1(c1), cut2(c2) { }
   bool cut(int n) const { return cut1.cut(n) && cut2.cut(n); }
-  CUT1 cut1;
-  CUT2 cut2;
+  const CUT1 & cut1;
+  const CUT2 & cut2;
   BOOST_STATIC_ASSERT((boost::is_base_of<Cut, CUT1>::value && boost::is_base_of<Cut, CUT2>::value));
 };
 template <typename CUT>
 struct CutInvert : public Cut {
   CutInvert(const CUT& c1) : poscut(c1) { }
   bool cut(int n) const { return !poscut.cut(n); }
-  CUT poscut;
+  const CUT & poscut;
   BOOST_STATIC_ASSERT((boost::is_base_of<Cut, CUT>::value));
 };
 
@@ -104,10 +104,10 @@
 
 int main() {
   const Cut& c1 = CutsAnd<Odd,Less>(Odd(), Less(5));
-  const auto c2 = Odd() && Less(5);
-  const auto c3 = c2 || Even();
-  const auto c4 = (Odd() && Less(5)) || Even();
-  const auto c5 = !( (Odd() && Less(5)) || Even() );
+  const Cut& c2 = Odd() && Less(5);
+  const Cut& c3 = c2 || Even();
+  const Cut& c4 = (Odd() && Less(5)) || Even();
+  const Cut& c5 = !( (Odd() && Less(5)) || Even() );
   for (int i = 0; i < 10; ++i) {
     cout << i << " ";
     cout << ((c1.cut(i)) ? "X" : " ");


More information about the Rivet mailing list