mardi 27 mars 2018

Explicit specialization of

My previous question about the same code: Template Specialization and std::map

I'm trying to specialize (full specialization) of class member template function and I have a code as follow and under clang compiler I'm getting an error explicit specialization of 'get<char> after instantiation and I was wondering that someone can help me to fix this compile error.

NOTE: Under Visual Studio 2017, declaring it ( std::string get<char>(mvs::Code); ) inside class and have the definition outside makes the code to compile but not under clang.

Here is the code:

#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) {}

    private:
        template <typename T> get( mvs::Code );

        typedef std::pair<std::string, std::function<std::string(mvs::Code)> > pair_type;
        std::map<mvs::Code, pair_type> map_ =
        {
            { mvs::Code1, { "Code1", [&](mvs::Code code) { return get<char>(code); } } }
        };
    };

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

        return {};
    }

    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