Belle II Software development
Visitor< operation > Struct Template Reference

This is a class template which takes a template class operation as template argument. More...

#include <CutNodes.h>

Public Member Functions

bool operator() (const double &val0, const double &val1)
 double double overload with double comparison.
 
bool operator() (const double &val0, const int &val1)
 double int overload with double comparison.
 
bool operator() (const double &val0, const bool &val1)
 double bool overload with double comparison.
 
bool operator() (const int &val0, const int &val1)
 int int overload with int comparison.
 
bool operator() (const int &val0, const bool &val1)
 int bool overload with int comparison.
 
bool operator() (const int &val0, const double &val1)
 int double overload with double comparison.
 
bool operator() (const bool &val0, const bool &val1)
 bool bool overload with bool comparison.
 
bool operator() (const bool &val0, const double &val1)
 bool double overload with double comparison.
 
bool operator() (const bool &val0, const int &val1)
 bool int overload with int comparison.
 

Detailed Description

template<template< typename type > class operation>
struct Belle2::Visitor< operation >

This is a class template which takes a template class operation as template argument.

This allows passing the functional class templates e.g std::greater<T>, which are templates themselves.

In the Nodes we often have to compare two node evaluation results with each other. They are of type variant<double, int, bool>. Variants cannot be compared to each other directly, you have to extract the values and compare them. This gives nine different combinations for two variants. C++ introduced the std::visit concept for this purpose of variant evaluation. std::visit takes a Visitor class and the variants as parameters. One way to write a Visitor is the following way, where a operator() overload is supplied for every data type combination the variants can have. The visitor has to be exhaustive (every data type combination must be covered), and every operator() overload has to have the same return type.

We have to do this comparisons for all comparison operators e.g ==, !=, > ... We can do this by passing the corresponding functional class template e.g std::equal_to<T>, std::not_equal_to<T>, std::greater<T> The datatype T is substituted in the operator() overload depending on the data type combination.

When comparing double/int and a bool the double/int overload of the functionals are used to disable implicit conversion to bool: std::equal_to<bool>{}(1.2, true) ==> true; 1.2 is implicitly converted to true, because of std::equal<bool> std::equal_to<double>{}(1.2, true) ==> false; true is implicity converted to 1.0, because of std::equal<double>

Definition at line 55 of file CutNodes.h.

Member Function Documentation

◆ operator()() [1/9]

bool operator() ( const bool &  val0,
const bool &  val1 
)
inline

bool bool overload with bool comparison.

Definition at line 101 of file CutNodes.h.

102 {
103 return operation<bool> {}(val0, val1);
104 }

◆ operator()() [2/9]

bool operator() ( const bool &  val0,
const double &  val1 
)
inline

bool double overload with double comparison.

Definition at line 108 of file CutNodes.h.

109 {
110 return operation<double> {}(val0, val1);
111 }

◆ operator()() [3/9]

bool operator() ( const bool &  val0,
const int &  val1 
)
inline

bool int overload with int comparison.

Definition at line 115 of file CutNodes.h.

116 {
117 return operation<int> {}(val0, val1);
118 }

◆ operator()() [4/9]

bool operator() ( const double &  val0,
const bool &  val1 
)
inline

double bool overload with double comparison.

Definition at line 73 of file CutNodes.h.

74 {
75 return operation<double> {}(val0, val1);
76 }

◆ operator()() [5/9]

bool operator() ( const double &  val0,
const double &  val1 
)
inline

double double overload with double comparison.

Definition at line 59 of file CutNodes.h.

60 {
61 return operation<double> {}(val0, val1);
62 }

◆ operator()() [6/9]

bool operator() ( const double &  val0,
const int &  val1 
)
inline

double int overload with double comparison.

Definition at line 66 of file CutNodes.h.

67 {
68 return operation<double> {}(val0, val1);
69 }

◆ operator()() [7/9]

bool operator() ( const int &  val0,
const bool &  val1 
)
inline

int bool overload with int comparison.

Definition at line 87 of file CutNodes.h.

88 {
89 return operation<int> {}(val0, val1);
90 }

◆ operator()() [8/9]

bool operator() ( const int &  val0,
const double &  val1 
)
inline

int double overload with double comparison.

Definition at line 94 of file CutNodes.h.

95 {
96 return operation<double> {}(val0, val1);
97 }

◆ operator()() [9/9]

bool operator() ( const int &  val0,
const int &  val1 
)
inline

int int overload with int comparison.

Definition at line 80 of file CutNodes.h.

81 {
82 return operation<int> {}(val0, val1);
83 }

The documentation for this struct was generated from the following file: