[BOOST]BOOST_AUTO_TEST_CASE_TEMPLATE vs BOOST_AUTO_TEST_CASE

Hi,
Scenario1:
Both files are present in the same Project BoostUnitTest.
fileA:
typedef boost::mpl::list

[Please do not mail me a copy of your followup] boost-users@lists.boost.org spake the secret code <518813FAAE539546847B8F61C0C9B2FA9B7B2388@SGPMBX06.APAC.bosch.com> thusly:
Why is the behaviour different in these 2 scenarios? How is Boost able to differenciate between the 2 test cases in Scenario1?
The difference is that non-template test cases are generated statically with unique names that cannot violate the one-definition rule. When you use BOOST_AUTO_TEST_CASE in multiple translation units inside the same test suite (which is really just a glorified namespace), the test cases must have unique names in order to not violate the one definition rule. When you use BOOST_AUTO_TEST_CASE_TEMPLATE, you get a uniquely named static instance of a class whose constructor registers the dynamically generated test cases for each of the template arguments. The same templatized code appears in each translation unit, but C++ allows the linker to discard all but one of the multiple instantiations of the same template. In order to provide this explanation, what I did was to take your template example code and expand the BOOST_AUTO_TEST_CASE_TEMPLATE macro until it was resolved down into actual code. -- "The Direct3D Graphics Pipeline" free book http://tinyurl.com/d3d-pipeline The Computer Graphics Museum http://computergraphicsmuseum.org The Terminals Wiki http://terminals.classiccmp.org Legalize Adulthood! (my blog) http://legalizeadulthood.wordpress.com

Hemanth Choudary M V (RBEI/ETA1
Why is the behaviour different in these 2 scenarios? How is Boost able to differenciate between the 2 test cases in Scenario1?
I think what it essentially comes to is this: If you have in header H: class A{ public: void test_method(); } void A::test_method() {} // note NO inline and include this header in 2 C++ files A and B linker will complain. If on the other hand you have this in H: template<typename Foo> class A{ public: void test_method(); } template<typename Foo> void A<Foo>::test_method() {} // inline implied Linker is required to merge multiple definitions from different translation units and program builds fine. These are rules of C++. HTH, Gennadiy
participants (3)
-
Gennadiy Rozental
-
Hemanth Choudary M V (RBEI/ETA1)
-
legalize+jeeves@mail.xmission.com