以静态方法返回decltype(auto),获取错误(vs2017),但可以工作于(vs2012)

时间:2019-01-07 08:36:27

标签: c++ c++14 auto decltype

static decltype(auto) Get(XML_Serializer& arcSer)
{
    return TDataConverter<TDataConverterAttribute>::Get(arcSer, DT_TypeDescriptor::Instance().GetAttribute<TVal, DT_DataConverterAttribute>());
};

typedef typename DT_TypeManipulation::RemoveReference<decltype(Get(*reinterpret_cast<XML_Serializer*>(NULL)))>::Result  Type;

不适用于C ++ 14(Visual Stdio 2017 / C ++ 17)

  

错误C3779:“ XML_TDataConverterProvider :: Get”:返回“ decltype(auto)”的函数在定义之前不能使用

template<class TVal>
class XML_TDataConverterProvider
{
   private:
        template<class TDataConverterAttribute>
        struct TDataConverter
        {
            static auto Get(XML_Serializer& arcSer, TDataConverterAttribute apcDataConverterAttribute)
            -> decltype(apcDataConverterAttribute->GetDataConverter())
            {
                ASSERT(apcDataConverterAttribute);
                return apcDataConverterAttribute->GetDataConverter();
            }
        };

        template<>
        struct TDataConverter<DT_DataConverterAttribute const* const>
        {
            static DT_DataConverter& Get(XML_Serializer& arcSer, DT_DataConverterAttribute const* const apcDataConverterAttribute)

            {
                ASSERT(!apcDataConverterAttribute);
                if (apcDataConverterAttribute) {}
                return arcSer.mcConv;
            }
        };
        typedef decltype(DT_TypeDescriptor::Instance().GetAttribute<TVal, DT_DataConverterAttribute>()) TDataConverterAttribute;

    public:
        static auto Get(XML_Serializer& arcSer)
        -> decltype(TDataConverter<TDataConverterAttribute>::Get(arcSer, DT_TypeDescriptor::Instance().GetAttribute<TVal, DT_DataConverterAttribute>()))
        {
            return TDataConverter<TDataConverterAttribute>::Get(arcSer, DT_TypeDescriptor::Instance().GetAttribute<TVal, DT_DataConverterAttribute>());
        };


        typedef typename DT_TypeManipulation::RemoveReference<decltype(Get(*reinterpret_cast<XML_Serializer*>(NULL)))>::Result  Type;

};

并且正在Visual Studio 2012 / C ++ 11中运行

要运行此代码,在C ++ 11代码中做了什么更改?

0 个答案:

没有答案