It can be done, it can be approximated, but how much work are you willing to put into making this expression style work?
I only ask because the code below illustrates about 1/200 of what you'd actually need to cleanly pull off this semantic modification.
Soma
Code:
template
<
typename type_F
>
struct lhs_type
{
lhs_type
(
const type_F & value_f
):
value_m(value_f)
{
}
const type_F & value_m;
};
template
<
typename type_F
>
lhs_type<type_F> lhs
(
const type_F & lhs_f
)
{
return(lhs_type<type_F>(lhs_f));
}
template
<
typename type_F
>
struct rhs_type
{
rhs_type
(
const type_F & value_f
):
value_m(value_f)
{
}
const type_F & value_m;
};
template
<
typename type_F
>
rhs_type<type_F> rhs
(
const type_F & rhs_f
)
{
return(rhs_type<type_F>(rhs_f));
}
template
<
typename lhs_F,
typename rhs_F
>
struct lor_type
{
lor_type
(
const lhs_F & lhs_f,
const rhs_F & rhs_f
):
lhs_m(lhs_f),
rhs_m(rhs_f)
{
}
const lhs_F & lhs_m;
const rhs_F & rhs_m;
};
template
<
typename lhs_F,
typename rhs_F
>
lor_type<lhs_F, rhs_F> operator ||
(
const lhs_type<lhs_F> & lhs_f,
const rhs_type<rhs_F> & rhs_f
)
{
return(lor_type<lhs_F, rhs_F>(lhs_f.value_m, rhs_f.value_m));
}
template
<
typename lhs_F,
typename rhs_lhs_F,
typename rhs_rhs_F
>
bool operator ==
(
const lhs_F & lhs_f,
const lor_type<rhs_lhs_F, rhs_rhs_F> & rhs_f
)
{
return((lhs_f == rhs_f.lhs_m) || (lhs_f == rhs_f.rhs_m));
}
struct operator_placeholder_type{} operator_placeholder;
template
<
typename lhs_F
>
lhs_type<lhs_F> operator ||
(
const lhs_F & lhs_f,
const operator_placeholder_type & rhs_f
)
{
return(lhs_type<lhs_F>(lhs_f));
}
template
<
typename lhs_F,
typename rhs_F
>
lor_type<lhs_F, rhs_F> operator ||
(
const lhs_type<lhs_F> & lhs_f,
const rhs_F & rhs_f
)
{
return(lor_type<lhs_F, rhs_F>(lhs_f.value_m, rhs_f));
}
#include <iostream>
#define my_log_or || operator_placeholder ||
int main()
{
if(3 == (lhs(3)||rhs(5)))
{
std::cout << '(' << 3 << ':' << 3 << ':' << 5 << ')' << '\n';
}
if(4 == (lhs(3)||rhs(5)))
{
std::cout << '(' << 4 << ':' << 3 << ':' << 5 << ')' << '\n';
}
if(5 == (lhs(3)||rhs(5)))
{
std::cout << '(' << 5 << ':' << 3 << ':' << 5 << ')' << '\n';
}
if(6 == (6 my_log_or 8))
{
std::cout << '(' << 6 << ':' << 6 << ':' << 8 << ')' << '\n';
}
if(7 == (6 my_log_or 8))
{
std::cout << '(' << 7 << ':' << 6 << ':' << 8 << ')' << '\n';
}
if(8 == (6 my_log_or 8))
{
std::cout << '(' << 8 << ':' << 6 << ':' << 8 << ')' << '\n';
}
return(0);
}