If I have a map<key, value> some_map, can I create a vector of the keys also, 
vector<key const &> ref_vec? I can create a vector<key const *> ptr_vec.

I'm thinking of my Bibtex data base of course.

/** All Bibliography keys derive from this base class, and need only define
 *  code() to be instantiated.
 */
class BibKey {
public:
        enum Code {
                BIBLIO_CODE,
                BIBTEX_CODE
        };

        virtual ~BibKey() {}
        virtual BibKey::Code code() const = 0;
        std::string const & get() const { return key_; }
private:
        std::string key_;
};


class BibtexKey : public BibKey {
public:
        BibKey::Code code() const { return BibKey::BIBTEX_CODE; }
};


/** The BibTeX database stores a map of the data so,
 *   where Bibitem is the info
 */
typedef std::map<BibtexKey, Bibitem> BMap;
///
BMap data_;

/** But it also stores a vector of the keys to pass back to the
 *   citation dialog. Note that the citation dialog gets a vector of Bibkeys,
 *   not BibtexKeys or BiblioKeys.
 */
std::vector<BibKey const *> keys_;

Once I have the data, I can create the keys_, so:

        keys_.resize(data_.size());
        std::vector<BibKey const *>::iterator key_it = keys_.begin();

        BMap::const_iterator map_it  = data_.begin();
        BMap::const_iterator map_end = data_.end();
        for (; map_it != map_end; ++map_it, ++key_it) {
                *key_it = &map_it->first;
        }

But I can't do it if the keys_ is a vector of references, not pointers. Is 
this impossible?

Angus

Reply via email to