mardi 27 mars 2018

Template Specialization and std::map

I'm trying to create map of Code with it's corresponding text and call function. I'm getting compile error and I can't figure out what is wrong with my code, std::map initialization. Can someone please explain what I'm doing wrong and how can I fix this:

#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <utility>
#include <map>

namespace mvs
{
    enum Code
    {
        Code0  = -1,
        Code1  = -2,
        Code2  = 1,

        CodeCount
    };
}

class CompositeFile
{
public:
    CompositeFile(std::string const& name) : name_(name) {}

    template <typename T>
    long readEx(mvs::Code code, std::vector<T>& buffer)
    {
         return 0;
    }

    std::string readString(mvs::Code code)
    {
        return {};
    }

private:
    std::string name_;
};

namespace mh
{
     class CompositeFileEx : public CompositeFile
     {
     public:
        CompositeFileEx(std::string const& name) : CompositeFile(name) {}

        template <typename T>
        std::string get(mvs::Code code)
        {
            std::vector<T> buffer;
            readEx(code, buffer);

            return {};
        }

    private:
        typedef std::pair<std::string, std::function<std::string(mvs::Code)> > pair_type;
         **std::map<mvs::Code, pair_type> map_ =
         {
             { mvs::Code1, { "Code1", get<char>(mvs::Code1) } }
         };**
     };

     template <>
     std::string CompositeFileEx::get<char>(mvs::Code code)
     {
         return readString( code );
     }
}

int main(int argc, char** argv)
{
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire