11#ifndef RANDOM_GENERATORS_H
22#define RANDOM_GENERATORS_H
33
4+ #include < array>
5+ #include < memory>
46#include < random>
57#include < iostream>
68
79struct float_number_generator {
8- virtual double new_float () { return 0 ; }
9- virtual std::string describe () { return " abstract class " ; }
10+ virtual double new_float () = 0;
11+ virtual std::string describe () = 0;
1012};
1113
1214struct uniform_generator : float_number_generator {
@@ -80,16 +82,20 @@ struct simple_int64 : float_number_generator {
8082 double new_float () override { return gen (); }
8183};
8284
83- std::vector<std::string> model_names = {" uniform" , " one_over_rand32" ,
84- " simple_uniform32" , " simple_int32" ,
85- " int_e_int" , " simple_int64" };
86- std::unique_ptr<float_number_generator>
85+ constexpr std::array<const char *, 6 > model_names = {
86+ " uniform" , " one_over_rand32" ,
87+ " simple_uniform32" , " simple_int32" ,
88+ " int_e_int" , " simple_int64"
89+ };
90+
91+ inline std::unique_ptr<float_number_generator>
8792get_generator_by_name (std::string name) {
8893 std::cout << " available models (-m): " ;
8994 for (std::string name : model_names) {
9095 std::cout << name << " " ;
9196 }
9297 std::cout << std::endl;
98+
9399 // This is naive, but also not very important.
94100 if (name == " uniform" ) {
95101 return std::unique_ptr<float_number_generator>(new uniform_generator ());
@@ -111,4 +117,4 @@ get_generator_by_name(std::string name) {
111117 return std::unique_ptr<float_number_generator>(new uniform_generator ());
112118}
113119
114- #endif
120+ #endif
0 commit comments