The two new form of so_5::api::run_so_environment() routines introduced. One of them receives lambda or std::function object as initialization function. It allows to write like this:
int
main( int argc, char ** argv )
{
try
{
so_5::api::run_so_environment(
[argc, argv]( so_5::rt::so_environment_t & env ) {
const int meetings = 2 == argc ? std::atoi( argv[1] ) : 10;
init( env, meetings );
},
std::move(
so_5::rt::so_environment_params_t()
.add_named_dispatcher(
"active_obj",
so_5::disp::active_obj::create_disp() ) ) );
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}
The another allows to edit semiprepared so_5::rt::so_environment_params_t object by function (or lambda, or std::function object):
int
main( int argc, char ** argv )
{
try
{
so_5::api::run_so_environment(
[argc, argv]( so_5::rt::so_environment_t & env ) {
const std::size_t ITERATIONS = 2 == argc ?
static_cast< std::size_t >(std::atoi( argv[1] )) :
10u;
auto coop = env.create_coop(
so_5::rt::nonempty_name_t( "test_coop" ),
so_5::disp::active_obj::create_disp_binder(
"active_obj" ) );
coop->add_agent( new a_runner_t( env, ITERATIONS ) );
env.register_coop( std::move( coop ) );
},
[]( so_5::rt::so_environment_params_t & p ) {
p.add_named_dispatcher(
"active_obj",
so_5::disp::active_obj::create_disp() );
p.exception_reaction(
} );
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}