Krishna,
> deal.ii makes heavy use of templates for spatial-dimension independent
> programming. However, as already acknowledged in the FAQ, compiling
> template-heavy code takes a long time.
>
> Since the number cases are only 3 (possible spatial dimensions), it strikes me
> that the variadic arguments feature (facilitated by the cstdarg.h header file)
> might be a slightly bit more natural choice for this use case? Apologies if I
> am wrong about this, since I am a novice C++ user.
> Can the developers/users of deal.ii provide an objective reasoning of why they
> went the template-route instead of variadic arguments?
It took me a good long while to think through how one would use variadic
arguments. Let's take a function like this one:
void
VectorTools::interpolate_boundary_values
(const Mapping< dim, spacedim > & mapping,
const DoFHandlerType< dim, spacedim > & dof,
const std::map< types::boundary_id, const Function< spacedim, number > *>
& function_map,
std::map< types::global_dof_index, number > & boundary_values,
const ComponentMask & component_mask = ComponentMask())
https://dealii.org/developer/doxygen/deal.II/namespaceVectorTools.html#a187aeb575be07bc47cb3dea1a47aaf88
If you want to avoid making this function a template, then the only real
option you have is to declare it as
void VectorTools::interpolate_boundary_values (...);
with variadic arguments. This way, you can pass in a Mapping<1>, Mapping<2>,
Mapping<3>, or if you want to Mapping<1,3> as first argument, and then
internally figure out what the argument actually represents. But there are
quite a number of downsides:
* Figuring out what you actually got has to happen at run-time, so it has
a performance impact
* The compiler can't do any type checking: If you pass a DoFHandler<1,3> as
first argument, nobody tells you that that's wrong. Or a pointer-to-mapping
instead of reference-to-mapping. You will only get an error message at
run-time, and the error is going to say "You passed something, but it
doesn't match what we expected". There is no further information what the
something might be.
* Arguments cannot be passed by reference to variadic functions. For big
objects such as triangulations, that means that one would have to use
pointers, but that's decidedly against the spirit of C++.
So it's a fun exercise to think through how one could use variadic functions
for what we want to do in deal.II. But it's not the most convenient way :-)
Cheers
W.
--
------------------------------------------------------------------------
Wolfgang Bangerth email:
bang...@colostate.edu
www:
http://www.math.colostate.edu/~bangerth/