A
Adam Markiewicz
I'm designing a container class similar to those in STL. It is implemented
as a template with two parameters: contained type and an allocator.
template <typename Type, typename Allocator>
class FixedArray
{
...
}
Now, to write a function that takes FixedArray as a param to support
different allocators I would need (example):
template <typename Allocator>
float average(const FixedArray<float, Allocator>& array);
However array is const, so Allocator wouldn't be needed at all. Is would be
much simpler to write:
float average(const FixedArray<float>& array);
This syntax can be provided by specifying a suitable copy constructor, but
I want to avoid unnecessary copying overhead. Is there some other
clean solution to this problem?
as a template with two parameters: contained type and an allocator.
template <typename Type, typename Allocator>
class FixedArray
{
...
}
Now, to write a function that takes FixedArray as a param to support
different allocators I would need (example):
template <typename Allocator>
float average(const FixedArray<float, Allocator>& array);
However array is const, so Allocator wouldn't be needed at all. Is would be
much simpler to write:
float average(const FixedArray<float>& array);
This syntax can be provided by specifying a suitable copy constructor, but
I want to avoid unnecessary copying overhead. Is there some other
clean solution to this problem?