Я совершенно новичок в C ++. Я использую std :: map с GCC. Поскольку (на мой взгляд) вывод std :: map с помощью GDB трудно читать. Я хочу экспортировать свою карту в вектор.
Теперь я уже разобрался (с некоторыми полезными постами с этого форума) :), как экспортировать карту в вектор. Теперь, если я правильно понял ссылку на c ++, std :: map не является потокобезопасным. Поэтому я строю Mutex Arround STD :: map
template<typename Mutex_Type_T, typename Key_Type_T, typename Mapped_Type_T>
class CConcurrent_Dictionary
{
public:
CConcurrent_Dictionary();
class CSingle_Element
{
public:
Key_Type_T key = { };
Mapped_Type_T mapped_type = { };
};
/**
* Exports all contect of std::map to a vector
* @param mutex_timeout Mutex timeout
* @return Vector with all contents of std::map
*/
std::vector<CSingle_Element> Export(const uint32_t mutex_timeout) const;
private:
const Mutex_Type_T mutex;
map<Key_Type_T, Mapped_Type_T> dictionary;
};
Реализация Export () выглядит следующим образом
template<typename Mutex_Type_T, typename Key_Type_T, typename Mapped_Type_T>
std::vector<CConcurrent_Dictionary<Mutex_Type_T, Key_Type_T, Mapped_Type_T>::CSingle_Element> CConcurrent_Dictionary<Mutex_Type_T, Key_Type_T, Mapped_Type_T>::Export(const uint32_t mutex_timeout) const
{
std::vector<CSingle_Element> res = {};
CLock_Guard_New<Mutex_Type_T> lock(mutex);
if(false == lock.Lock(mutex_timeout))
{
return res;
}
//export all Elements
for(const auto& single_element : dictionary)
{
CSingle_Element single = {};
single.key = single_element.first;
single.mapped_type = single_element.second;
res.push_back(single);
}
return res;
}
Однако проблема не компилируется
note: expected a type, got 'NDictionary::CConcurrent_Dictionary<Mutex_Type_T, Key_Type_T, Mapped_Type_T>::CSingle_Element'
error: template argument 2 is invalid
error: prototype for 'int NDictionary::CConcurrent_Dictionary<Mutex_Type_T, Key_Type_T, Mapped_Type_T>::Export(uint32_t) const' does not match any in class 'NDictionary::CConcurrent_Dictionary<Mutex_Type_T, Key_Type_T, Mapped_Type_T>'
Похоже, что аргумент шаблона вектора принят неправильно.
Для моего понимания я бы ожидал
CConcurrent_Dictionary :: CSingle_Element
быть единственным аргументом шаблона для std :: vector. Так вы могли бы помочь мне? Чего мне не хватает?