Re: Template redundancy
On Feb 23, 6:58 pm, Kaba <n...@here.com> wrote:
I dream of some kind of scope that I could use something like this:
template <class Key, class Value, class ExtractKey,
class Hash, class Pred, class UniformAllocator>
UnorderedBase<Key, Value, ExtractKey, Hash, Pred, UniformAllocator>
{
// All the function implementations here are scoped under the class
above.
}
Of course, you get this effect if you place the member function
definitions in the class definition. But I want to separate the class
definition and member function definitions for the sake of documentation
(so that it is easy to see the class interface).
As came up in another thread, I've been dreaming of a similar syntax.
template <class Key, class Value, class ExtractKey,
class Hash, class Pred, class UniformAllocator>
{
typedef UnorderedBase<Key, Value, ExtractKey, Hash, Pred,
UniformAllocator> _UnorderedBase;
_UnorderedBase& _UnorderedBase::do_something( _UnorderedBase& ub )
{
...
}
}
Yours has the advantage of encasing a class in the template block,
which makes it more specified which seems more OOP. The advantage of
mine is it's more applicable to many different situations that aren't
necessarily OOP.
The thread this came up in was about was, similarly, the redundancy of
initializing classes where you might have ten template parameters just
defining the base, then you typedef the base with all those template
parameters, which is hazardous if the template parameters change. It's
also duplicate, redundant code. Many syntaxes were proposed for said
problem.
I actually seemed to find it!
http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/ed24d627bd1f4b95?q=
I see your problem as essentially, an extension of the problem noted
in that thread.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]