A program using class template, pair, vector

I'm trying to program the following: A template class map having a pointer to a vector that contains elements std::pair<T,Q>, where T and Q are template types. It's supposed to work similarly to std::map and T is 'key' type, whereas Q stands for 'value' type. Besides the following should be implemented: 1. Constructor & destructor. 2. Function empty returning bool (if the object is empty). 3. Function size (using count_if) 4. Function clear that deletes all vector records. 5. Operator [] which allows for: map["PI_value"] = 3.14; It should use function find 6. Operators =, ==, !=, >> (using equal function)

I've been trying to code the above task, but have stuck on the code below. Do you have any ideas to repair this mess?

#include <iostream>
#include <tuple>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

template <typename T, typename Q>
class mapa
    vector<std::pair<T,Q>>* ptr;
    /**< DEFAULT CONSTRUCTOR/////////////////////////// */
        ptr = new vector<std::pair<T,Q>>;
    /**< DESTRUCTOR////////////////////////////////////// */
    ~mapa(){ delete ptr;}
    /**< EMPTY()////////////////////////////// */
    bool empty()
            return false;
            return true;
    /**< SIZE()///////////////////////////////// */
    int size()
        return ptr->size();
    /**< CLEAR()///////////////////////////////// */
    void clear()
        ptr->clear(ptr->begin(), ptr->end());
    /**< OPERATOR[]/////////////////////////////////////////// */
    vector<std::pair<T,Q>>* & operator[](T key)
        auto ptr2 = ptr;
            std::pair<T,Q> para;

            para.first = key;
            para.second = 0;

            auto ptr2 = find_if( ptr->begin(), ptr->end(),
            [](std::pair<T,Q> example,T key)
        return ptr2;
}; //class end


The lambda provided to std::find_if is declared wrong.

If you see e.g. this reference for std::find_if, you will see that the functions should be like

bool pred(const Type &a)

That means the lambda should be something like

[&key](const std:pair<T, Q>& element) { return element.first == key }

There are also other problems with your operator[] function, like that it should return Q& instead of a reference to the vector pointer. You should also remember that std::find_if returns an iterator to the found element, or end() if not found.

Need Your Help

Boost.lockfree performance on RHEL 5.3

c++ linux boost lock-free rhel5

I'm trying to use the Boost::lockfree::spsc_queue for an application that will be supported on multiple platforms. I tried the spsc_queue.cpp example from boost_1_55_0/libs/examples/lockfree on Win...