From e2bf3ec3c0567780ca1624784da719fc6ff1fdcc Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 26 Aug 2020 11:58:46 +0200 Subject: [PATCH] allow eoBit to be templatized on its value type This helps avoiding the infamous std::vector specialization, which (wrongly) exchange space for speed. --- eo/src/ga/eoBit.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/eo/src/ga/eoBit.h b/eo/src/ga/eoBit.h index 040e57418..71c6aa62b 100644 --- a/eo/src/ga/eoBit.h +++ b/eo/src/ga/eoBit.h @@ -59,22 +59,27 @@ Example of a complete test program that use various bitstrings operators: Based on STL's std::vector specialization. */ -template class eoBit: public eoVector + +template + +class eoBit: public eoVector { public: + using ScalarType = ScalarT; - using eoVector< FitT, bool >::begin; - using eoVector< FitT, bool >::end; - using eoVector< FitT, bool >::resize; - using eoVector< FitT, bool >::size; + using eoVector< FitT, ScalarType >::begin; + using eoVector< FitT, ScalarType >::end; + using eoVector< FitT, ScalarType >::resize; + using eoVector< FitT, ScalarType >::size; /** * (Default) Constructor. * @param size Size of the binary std::string. * @param value Default value. */ - eoBit(unsigned size = 0, bool value = false): - eoVector(size, value) {} + eoBit(unsigned size = 0, ScalarType value = false): + // eoBit(unsigned size, ScalarType value): + eoVector(size, value) {} /// My class name. virtual std::string className() const @@ -91,7 +96,7 @@ public: EO::printOn(os); os << ' '; os << size() << ' '; - std::copy(begin(), end(), std::ostream_iterator(os)); + std::copy(begin(), end(), std::ostream_iterator(os)); } /**