I am trying to solve some exercises but have been stuck for a very long time now and can't seem to find any solutions online nor on the exercise page, so I hope someone can help me understand and solve this.
I was given the following function that I were to create a class to that accepts the syntax that is used in the function.
container_t example_1() {
auto value1 = 5.0;
auto value2 = 30.0;
auto v = container_t{};
auto env = v.environment();
auto A = v("A", 1);
auto B = v("B", 0);
auto C = v("C", 0);
v(A + B >>= C, value1);
v(C >>= B + A, value2);
return v;
The idea is that v("A", 1);
should save the alias A to a symbol table with its corresponding value. That I seem to have figured out.
The hard part for me is how I can also allow the expression: A + B >>= C
whilst saving it as an class object of some sort, or perhaps just to a different symbol table. Please note that the >>=
operator should be overloaded and is to be considered as an arrow ->
indicating that if you take A + B you get C.
I've created the following class and operator overload but am missing the expression part. Any help would be appreciated!
class container_t {
environment env;
public:
environment* environment() {
return &env;
}
container_t() { };
template <typename T, typename Data = std::size_t>
container_t& operator()(T molecule, Data value) {
if (is_string_v<T>) {
env.insertMoleculeToSymbolTable(molecule, value);
return *this;
} else if (std::is_arithmetic<T>::value) {
// I never get this far ...
std::cout << "Is reaction" << std::endl;
}
}
};