std::list<entry>::const_iterator and a 0 object

H

Hicham Mouline

hi,

I have a class an excerpt of which is:

class histo_data {
public:
///
/// Public Types
///
typedef std::list<entry>::const_iterator const_iterator;
typedef std::list<entry>::iterator iterator;
typedef std::list<entry>::const_reverse_iterator const_reverse_iterator;
typedef std::list<entry>::reverse_iterator reverse_iterator;
typedef std::list<entry>::reference reference;
typedef std::list<entry>::const_reference const_reference;
typedef std::pair<const_iterator, const_iterator> const_range_t;
typedef std::pair<iterator, iterator> range_t;

///
/// Constructors
///
histo_data(const_iterator begin, const_iterator end);

private:
std::list<entry> data_;
};



"entry" is a struct with boost::gregorian::date and other primitive types.
I want to make an object histo_data which contains all the dates from
1/1/1970 to 1/1/2030 and all other primitive types are 0.
Ideally, I would like to write it along the lines of:

const histo_data zero_histo_data( ... , .... );

1. I suppose I need a different constructor. Make it templated on the
iterator type?
2. Make a new iterator to entry and pass these 2 iterators to the
constructor?

Regards,
 
Ö

Öö Tiib

hi,

I have a class an excerpt of which is:

class histo_data {
public:
///
/// Public Types
///
typedef std::list<entry>::const_iterator const_iterator;
typedef std::list<entry>::iterator iterator;
typedef std::list<entry>::const_reverse_iterator const_reverse_iterator;
typedef std::list<entry>::reverse_iterator reverse_iterator;
typedef std::list<entry>::reference reference;
typedef std::list<entry>::const_reference const_reference;
typedef std::pair<const_iterator, const_iterator> const_range_t;
typedef std::pair<iterator, iterator> range_t;

///
/// Constructors
///
histo_data(const_iterator begin, const_iterator end);

private:
  std::list<entry> data_;

};

"entry" is a struct with boost::gregorian::date and other primitive types..
I want to make an object histo_data which contains all the dates from
1/1/1970 to 1/1/2030 and all other primitive types are 0.

Why? It is usually pointless to fill lot of memory with sequence of
predictable data and zeroes. It may be useful for some optimization,
but then you need to describe the performance issue for us to
understand.
Ideally, I would like to write it along the lines of:

const histo_data  zero_histo_data( ...   ,   .... );

What are the "...."? What information do they give to constructor?
1. I suppose I need a different constructor. Make it templated on the
iterator type?
2. Make a new iterator to entry and pass these 2 iterators to the
constructor?

What iterators? You have tons of typedefs about iterators and
references and ranges but i don't see any meaningful usage or
description of usage of these.
 
J

Jeff Flinn

Hicham said:
hi,

I have a class an excerpt of which is:

class histo_data {
public:
///
/// Public Types
///
typedef std::list<entry>::const_iterator const_iterator;
typedef std::list<entry>::iterator iterator;
typedef std::list<entry>::const_reverse_iterator const_reverse_iterator;
typedef std::list<entry>::reverse_iterator reverse_iterator;
typedef std::list<entry>::reference reference;
typedef std::list<entry>::const_reference const_reference;
typedef std::pair<const_iterator, const_iterator> const_range_t;
typedef std::pair<iterator, iterator> range_t;

///
/// Constructors
///
histo_data(const_iterator begin, const_iterator end);

private:
std::list<entry> data_;
};



"entry" is a struct with boost::gregorian::date and other primitive types.
I want to make an object histo_data which contains all the dates from
1/1/1970 to 1/1/2030 and all other primitive types are 0.
Ideally, I would like to write it along the lines of:

const histo_data zero_histo_data( ... , .... );

1. I suppose I need a different constructor. Make it templated on the
iterator type?
2. Make a new iterator to entry and pass these 2 iterators to the
constructor?

While not answering your direct question, have you looked at the
reviewed/accepted boost.itl library. Your implied example looks like
exactly what ITL was designed to do, and in fact has examples directly
dealing with intervals of dates.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top