I would like to create something to use in Visual Studio (C++),maybe an extension, that will be used with two known functions inside. Let me try and explain. Let's say I have two functions start() and stop(). I usually use these functions like:
start();
do something...
stop();
Some times it might become kind of confusing to know what is starting and what is stopping:
start();
do something...
start();
do something...
start();
do something...
stop();
stop();
stop();
For me to understand what is starting and what is stopping I need to ident all the lines manually. I would like to create something like:
start(){
do something....
start(){
do something ...
}
}
Every time I close the start brackets the stop function will be close and the code will be much more organized.
Do you guys have any idea on how to accomplish this or something similar?
In C++11 you can wright such code, but you need to understand high order functions and c++ lambdas.
#include <iostream>
class Executor
{
public:
void perform(void (*routine)())
{
start();
routine();
stop();
}
void start() { std::cout << "start" << std::endl; }
void stop() { std::cout << "stop" << std::endl; }
};
int main()
{
Executor executor;
executor.perform([](){
std::cout << "perform 0" << std::endl;
});
executor.perform([](){
std::cout << "perform 1" << std::endl;
Executor executor;
executor.perform([](){
std::cout << "perform 10" << std::endl;
});
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With