14 #ifndef EMP_EVO_WORLD_REFLECT_H 15 #define EMP_EVO_WORLD_REFLECT_H 18 #include <type_traits> 20 #include "../base/assert.h" 21 #include "../meta/reflection.h" 34 template <
typename WORLD,
typename ORG>
35 void SetDefaultFitFun_impl(WORLD & world,
bool_decoy<decltype( declval<ORG>().GetFitness() )>) {
36 world.SetFitFun( [](ORG & org){
return (
double) org.GetFitness(); } );
39 template <
typename WORLD,
typename ORG>
40 void SetDefaultFitFun_impl(WORLD & world,
int_decoy<decltype( (
double) declval<ORG>() )>) {
41 world.SetFitFun( [](ORG & org){
return (
double) org; } );
44 template <
typename WORLD,
typename ORG>
45 void SetDefaultFitFun_impl(WORLD & world, ... ) {
46 world.SetFitFun( [](ORG & org){
47 emp_assert(
false,
"No default fitness function available");
54 template <
typename WORLD,
typename ORG>
55 void SetDefaultFitFun(WORLD & world) { SetDefaultFitFun_impl<WORLD, ORG>(world,
true); }
62 template <
typename WORLD,
typename ORG>
63 void SetDefaultMutFun_impl(WORLD & world,
bool_decoy<decltype( declval<ORG>().DoMutations( *((
Random*)
nullptr) ) )>) {
64 world.SetMutFun( [](ORG & org,
Random & random) {
65 return (
double) org.DoMutations(random);
69 template <
typename WORLD,
typename ORG>
70 void SetDefaultMutFun_impl(WORLD & world, ... ) {
71 world.SetMutFun( [](ORG & org,
Random & random) {
72 emp_assert(
false,
"No default DoMutations available");
79 template <
typename WORLD,
typename ORG>
80 void SetDefaultMutFun(WORLD & world) { SetDefaultMutFun_impl<WORLD, ORG>(world,
true); }
90 template <
typename WORLD,
typename ORG>
91 void SetDefaultPrintFun_impl(WORLD & world,
bool_decoy<decltype( declval<ORG>().
Print(std::cout) )>) {
92 world.SetPrintFun( [](ORG & org, std::ostream & os){ org.Print(os); } );
95 template <
typename WORLD,
typename ORG>
96 void SetDefaultPrintFun_impl(WORLD & world,
int_decoy<decltype( std::cout << declval<ORG>() )>) {
97 world.SetPrintFun( [](ORG & org, std::ostream & os){ os << org; } );
100 template <
typename WORLD,
typename ORG>
101 void SetDefaultPrintFun_impl(WORLD & world, ... ) {
102 world.SetPrintFun( [](ORG & org, std::ostream & os){
103 emp_assert(
false,
"No default Print function available");
109 template <
typename WORLD,
typename ORG>
115 template <
typename ORG>
116 auto Org2Genome(
bool_decoy< decltype( declval<ORG>().GetGenome() ) >)
117 -> std::decay_t< decltype( declval<ORG>().GetGenome() ) >;
119 template <
typename ORG>
120 ORG Org2Genome( ... );
123 template <
typename ORG>
132 template <
typename WORLD,
typename ORG>
133 void SetOrgGetGenome_impl(WORLD & world,
bool_decoy<decltype( declval<ORG>().GetGenome() )>) {
134 world.SetGetGenomeFun( [](ORG & org) ->
const auto & {
return org.GetGenome(); } );
137 template <
typename WORLD,
typename ORG>
138 void SetOrgGetGenome_impl(WORLD & world, ... ) {
139 world.SetGetGenomeFun( [](ORG & org) ->
const ORG & {
return org; } );
144 template <
typename WORLD,
typename ORG>
void SetDefaultPrintFun(WORLD &world)
Definition: World_reflect.h:110
A versatile and non-patterned pseudo-random-number generator (Mersenne Twister).
Definition: ce_random.h:52
decltype(Org2Genome< ORG >(true)) find_genome_t
Definition: World_reflect.h:124
bool bool_decoy
Definition: meta.h:95
If we are in emscripten, make sure to include the header.
Definition: array.h:37
#define emp_assert(...)
Definition: assert.h:199
void SetDefaultFitFun(WORLD &world)
Definition: World_reflect.h:55
void Print(const emp::vector< T > &v, std::ostream &os=std::cout, const std::string &spacer=" ")
Print the contects of a vector.
Definition: vector_utils.h:35
void SetDefaultMutFun(WORLD &world)
Definition: World_reflect.h:80
void SetDefaultGetGenomeFun(WORLD &world)
Definition: World_reflect.h:145
int int_decoy
Definition: meta.h:96