H
Hicham Mouline
Hi,
I have a situation where behind the scenes I implement a container either as
1. boost::array<type, max_size> + size_t current_size
this array would be contained in some class "Container" that behaves as
closely as possible to
standard containers, with the addition that it only considers elements
between 0 and current_size-1
so that
size() returns current_size ( can be variable )
unchecked [] returns the usual
begin() returns &...[0]
end() returns &...[current_size-1]
I would make a new random access iterator that takes into account
current_size
I would be guaranteed this is on the stack
2. std::vector<type>
This may and probably is on the heap.
I would like to access both types with the same interface such that:
template <typename traits>
class MyClass {
// member container
// depending on Traits
Container<traits::max_size> data_; // this "is" either 1 or 2
// implementation
// data_.begin()
// data_.end()
// std::lower_bound( data_.begin(), data_.end(). .....)
};
and I could access data_ as if it was a "standard" container. Basically I
wanna hide the current_size case when Container is array<>,
note its max size is available in Traits. if max is 0 we use vector<>
otherwise array<>
I have then a primary template for Container (array<>) and an explicit
specialization on 0 (vector<>)
this forces me to rewrite all vector<> desired operations in Container as
forwarding operations that are just 1 liners,
which i think is a waste. In other words, I wish Container<0> to "be"
vector<>, but it is understood using inheritance is
woudl cause undefined behavior, in particular in case of virtual
destruction.
regards,
I have a situation where behind the scenes I implement a container either as
1. boost::array<type, max_size> + size_t current_size
this array would be contained in some class "Container" that behaves as
closely as possible to
standard containers, with the addition that it only considers elements
between 0 and current_size-1
so that
size() returns current_size ( can be variable )
unchecked [] returns the usual
begin() returns &...[0]
end() returns &...[current_size-1]
I would make a new random access iterator that takes into account
current_size
I would be guaranteed this is on the stack
2. std::vector<type>
This may and probably is on the heap.
I would like to access both types with the same interface such that:
template <typename traits>
class MyClass {
// member container
// depending on Traits
Container<traits::max_size> data_; // this "is" either 1 or 2
// implementation
// data_.begin()
// data_.end()
// std::lower_bound( data_.begin(), data_.end(). .....)
};
and I could access data_ as if it was a "standard" container. Basically I
wanna hide the current_size case when Container is array<>,
note its max size is available in Traits. if max is 0 we use vector<>
otherwise array<>
I have then a primary template for Container (array<>) and an explicit
specialization on 0 (vector<>)
this forces me to rewrite all vector<> desired operations in Container as
forwarding operations that are just 1 liners,
which i think is a waste. In other words, I wish Container<0> to "be"
vector<>, but it is understood using inheritance is
woudl cause undefined behavior, in particular in case of virtual
destruction.
regards,