1
votes

I was writing wrapper methods for Boost unordered map container. In boost Unordered Map there is a method begin() which returns an iterator to the first element.Actually in my wrapper class i want to return a std::Unordered_map::iterator instead of boost::unordered_map::iterator from my Begin method. Example code: template

boost::unordered_map<key, value> m_myMap;

boost::unordered::unordered_map::iterator MyWrapper<>::Begin()
{
    return m_myMap.begin();
}

In the above code i want to return std::Unordered_map::iterator Please help

1

1 Answers

2
votes

You can't. C++ is a strongly typed language.

The best you can do is

  • use std::unordered_map
  • Use type erasure to hide the implementation (boost::any_iterator or boost::any_range)

My spidy sense tells me that you should take the iterators by deduced template argument type, instead of hard-coding them into your algorithms.

template <typename Iterator>
void foo_algo(Iterator begin, Iterator end, int some_data) {
...