Hi,
It is an extension to one my previous post, where I needed help while
giving access to a sub_range for of an container.
In that problem , Mr Thorsten Ottosen, provided answer to all of my
queries (Many thanks to him ).
This time I am interested to provide indexed access to a vector with a
sub_range ,using permutation_iterator.
Here some codes are creating problem, while I am using sub_range with
permutation iterator.
To specify, I am providing a small test code.
typedef std::pairstd::size_t,std::size_t pair_t;
template<typename T>
class vector_e : private std::vector<T>{
public:
typedef vector_e<T> self_type;
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
typedef boost::sub_range range;
typedef boost::sub_range<const self_type> const_range;
typedef typename std::vector<T>::size_type size_type;
typedef std::vector<int> index_type;
typedef typename boost::permutation_iterator index_iterator;
typedef typename boost::permutation_iterator const_index_iterator;
vector_e() : std::vector<T>(){}
using std::vector<T>::begin;
using std::vector<T>::end;
using std::vector<T>::operator [];
using std::vector<T>::insert;
index_iterator begin_i(const index_type& i){
return boost::make_permutation_iterator(begin(),i.begin());
}
const_index_iterator begin_i(const index_type& i)const{
return boost::make_permutation_iterator(begin(),i.begin());
}
index_iterator end_i(const index_type& i){
return boost::make_permutation_iterator(begin(),i.end());
}
const_index_iterator end_i(const index_type& i)const{
return boost::make_permutation_iterator(begin(),i.end());
}
range get_range(const pair_t& range){
return
boost::make_iterator_range(begin()+range.first,begin()+range.second);
}
const_range get_range(const pair_t& range)const{
return
boost::make_iterator_range(begin()+range.first,begin()+range.second);
}
range get_range(const index_type& i){
return
boost::make_iterator_range(boost::make_permutation_iterator(begin(),i.begin()),
boost::make_permutation_iterator(begin(),i.end()));
}
};
int main(int argc,char** argv) {
using namespace boost;
using namespace boost::assign;
using namespace boost::lambda;
using boost::lambda::_1;
typedef vector_e<int> elem_t;
typedef std::vector<int> index_t;
elem_t v;
int a[] = {00,10,20,30,40,50,60,70,80,90,100};
v.insert(v.end(),a,a+11);
const elem_t& cv = const_cast(v);
//v+= 00,10,20,30,40,50,60,70,80,90,100;
std::cout<<"original array : ";
std::for_each(v.begin(),v.end(),std::cout<<_1<<" ");
///For continuous ranges.
elem_t::range r = v.get_range(std::make_pair(1,5));
std::cout<
]
and
[
C=vector_e<int>::self_type
]
The questions are
1) Can anyone point out the problem ? (Is sub_range is typed by iterator
by any chance, or typed by container only ? )
2) This is aux question. How to make assign library work for my
inherited container (vector_e here ), like the commented line ?
any help is appreciated, and thanks to the community .
abir
--
Abir Basak, Member IEEE
Software Engineer, Read Ink Technologies
B. Tech, IIT Kharagpur
email: abir@abirbasak.com
homepage: www.abirbasak.com