Re: Boost unittest
On Aug 7, 9:18 am, Michael DOUBEZ <michael.dou...@free.fr> wrote:
saneman a =E9crit :
<acehr...@gmail.com> skrev i en meddelelse
news:012bcdc5-8af2-403a-ace7-12ffa1a3b588@1g2000pre.googlegroups.com...
On Aug 6, 12:34 pm, "saneman" <as...@asd.com> wrote:
// Types
std::vector<int> v;
v.push_back(22); //This gives an error!
You can't use the global namespace for everything.
Out of curiosity why not? Is it a special boost thing?
It is something specific to many compiled languages: you have
only one entry point of execution (i.e. main() in C++) and
code get executed from there only. The only exception in C++
being the construction of globals for initialisation. In all
cases code is executed from within a function.
Actually, as you point out later, this isn't true of C++. You
can add additional entry points anywhere you like, just by
defining a variable with static lifetime, e.g.:
static bool dummyForInitialization = (startUpFunction(), true) ;
(Generally speaking, I'd prefer having the startUpFunction
return a bool, and drop the comma operator. But I did it this
way to show that it can easily be done with any function.)
Concerning your question:
1. if you need only one value in your global, you can use:
std::vector<int> v(1,22);//vector of size one filled with 22
In this particular case, that's obviously the solution. More
generally, however, he could do something like:
std::vector< int > v ;
bool dummyForInitialization = (v.push_back( 22 ), true) ;
(I'm not saying that he should, of course:-). Only that the
possibility exists.)
2. For unit test, usual practice is to set up the environement before
the test such that tests are independant.
I'd say that that is almost a requirement, no?
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34