Is there any way to do pre-compile code expansion in test.cc?

14 views
Skip to first unread message

Lei Qiao

unread,
Aug 8, 2015, 11:09:41 PM8/8/15
to deal.II User Group
Dear all,

Now I have to template argument need to go through in a test.cc file.
But I don't want to write the code repeatedly or generate code by a script and paste a very long piece of boring code into the test.cc file. 

So, is there any way to do pre-compile code expansion by a loop in test.cc, just like in the *.inst.in file? 

Best,
Lei

Matthias Maier

unread,
Aug 8, 2015, 11:57:51 PM8/8/15
to dea...@googlegroups.com

On Sat, Aug 8, 2015, at 22:09 CDT, Lei Qiao <qiao...@gmail.com> wrote:

> [...]
>
> So, is there any way to do pre-compile code expansion by a loop in test.cc,
> just like in the *.inst.in file?

No, there is none.

Best,
Matthias

Wolfgang Bangerth

unread,
Aug 9, 2015, 11:58:46 AM8/9/15
to dea...@googlegroups.com
On 08/08/2015 10:09 PM, Lei Qiao wrote:
>
> Now I have to template argument need to go through in a test.cc file.
> But I don't want to write the code repeatedly or generate code by a script and
> paste a very long piece of boring code into the test.cc file.

You can do
template <typename T> void check () {
...code that uses type T...
}

int main () {
check<A>();
check<B>();
}

This way you only have to repeat the calls to check() for the template types A
and B, not the actual code.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@math.tamu.edu
www: http://www.math.tamu.edu/~bangerth/

Lei Qiao

unread,
Aug 9, 2015, 4:18:03 PM8/9/15
to deal.II User Group


On Sunday, August 9, 2015 at 10:58:46 AM UTC-5, bangerth wrote:
On 08/08/2015 10:09 PM, Lei Qiao wrote:
>
> Now I have to template argument need to go through in a test.cc file.
> But I don't want to write the code repeatedly or generate code by a script and
> paste a very long piece of boring code into the test.cc file.

You can do
   template <typename T> void check () {
     ...code that uses type T...
   }

   int main () {
     check<A>();
     check<B>();
   }

This way you only have to repeat the calls to check() for the template types A
and B, not the actual code.


Thanks.

That's almost my final solution. At the first I was just too lazy and got too many template parameters. 


Reply all
Reply to author
Forward
0 new messages