fix!(eoBit): defaults to char for scalar type

Since STL's vector of bool is not a vector of bool, `swap`ing bool elements in an eoBit can lead to errors.
Using `char` is a saner default.

Potential BREAKING CHANGE.
This commit is contained in:
Johann Dreo 2024-08-19 09:49:08 +02:00
commit 55b2f57d19
5 changed files with 9 additions and 9 deletions

View file

@ -41,7 +41,7 @@ template <class FitT>
class eoInitVirus: public eoInit< eoVirus<FitT> > { class eoInitVirus: public eoInit< eoVirus<FitT> > {
public: public:
eoInitVirus(unsigned _combien, eoRndGenerator<bool>& _generator ) eoInitVirus(unsigned _combien, eoRndGenerator<char>& _generator )
: combien(_combien), generator(_generator) {} : combien(_combien), generator(_generator) {}
virtual void operator()( eoVirus<FitT>& chrom) virtual void operator()( eoVirus<FitT>& chrom)
@ -58,7 +58,7 @@ public:
private : private :
unsigned combien; unsigned combien;
/// generic wrapper for eoFunctor (s), to make them have the function-pointer style copy semantics /// generic wrapper for eoFunctor (s), to make them have the function-pointer style copy semantics
eoSTLF<bool> generator; eoSTLF<char> generator;
}; };
/// Inits the virus with one bit to the left set to one /// Inits the virus with one bit to the left set to one
@ -66,7 +66,7 @@ template <class FitT>
class eoInitVirus1bit: public eoInit< eoVirus<FitT> > { class eoInitVirus1bit: public eoInit< eoVirus<FitT> > {
public: public:
eoInitVirus1bit(unsigned _combien, eoRndGenerator<bool>& _generator ) eoInitVirus1bit(unsigned _combien, eoRndGenerator<char>& _generator )
: combien(_combien), generator(_generator) {} : combien(_combien), generator(_generator) {}
virtual void operator()( eoVirus<FitT>& chrom) virtual void operator()( eoVirus<FitT>& chrom)
@ -81,6 +81,6 @@ public:
private : private :
unsigned combien; unsigned combien;
/// generic wrapper for eoFunctor (s), to make them have the function-pointer style copy semantics /// generic wrapper for eoFunctor (s), to make them have the function-pointer style copy semantics
eoSTLF<bool> generator; eoSTLF<char> generator;
}; };
#endif #endif

View file

@ -60,12 +60,12 @@ Example of a complete test program that use various bitstrings operators:
Based on STL's std::vector<bool> specialization. Based on STL's std::vector<bool> specialization.
*/ */
template <class FitT, class ScalarT = bool> template <class FitT, class ScalarT = char>
class eoBit: public eoVector<FitT, ScalarT> class eoBit: public eoVector<FitT, ScalarT>
{ {
public: public:
using ScalarType = ScalarT; using ScalarType = ScalarT;
using eoVector< FitT, ScalarType >::begin; using eoVector< FitT, ScalarType >::begin;
using eoVector< FitT, ScalarType >::end; using eoVector< FitT, ScalarType >::end;

View file

@ -68,7 +68,7 @@ eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT, float _b
// Then we can built a bitstring random initializer // Then we can built a bitstring random initializer
// based on boolean_generator class (see utils/rnd_generator.h) // based on boolean_generator class (see utils/rnd_generator.h)
eoBooleanGenerator<bool> * gen = new eoBooleanGenerator<bool>(_bias); eoBooleanGenerator<char> * gen = new eoBooleanGenerator<char>(_bias);
_state.storeFunctor(gen); _state.storeFunctor(gen);
eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(theSize, *gen); eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(theSize, *gen);
// store in state // store in state

View file

@ -115,7 +115,7 @@ inline bool eoUniformGenerator<bool>::operator()(void)
to easily generate random booleans with a specified bias to easily generate random booleans with a specified bias
\ingroup bitstring \ingroup bitstring
*/ */
template<class T=bool> template<class T=char>
class eoBooleanGenerator : public eoRndGenerator<T> class eoBooleanGenerator : public eoRndGenerator<T>
{ {
public : public :

View file

@ -56,7 +56,7 @@ int main() {
nkLandscapesEval<Solution> eval(N, K); nkLandscapesEval<Solution> eval(N, K);
// init // init
eoUniformGenerator<bool> uGen; eoUniformGenerator<char> uGen;
eoInitFixedLength<Solution> init(N, uGen); eoInitFixedLength<Solution> init(N, uGen);
// verif constructor // verif constructor