重载模板函数中的MSVC2015 decltype参数类型

Ros*_*ina 6 c++ c++11

以下程序是否符合C++ 11?如果是这样,你知道触发它的特定MSVC错误吗?和/或可能的解决方法?

#include <iostream>

struct A {};
struct B {};

constexpr A aaa = {};
constexpr B bbb = {};

template <typename T>
void foo(T, decltype(aaa)) { std::cout << "a"; }

template <typename T>
void foo(T, decltype(bbb)) { std::cout << "b"; }
// ^ C2995 'void foo(T,unknown-type)': function template has already been defined

int main()
{
    foo(0, aaa);
    foo(0, bbb);
}
Run Code Online (Sandbox Code Playgroud)

如果替换实际类型decltype然后它可以工作,但实际上这些类型太复杂而不能重现,我宁愿不为它们添加别名.

Vio*_*ffe 4

适用于我(VS 2015 / v140),并进行以下细微修改:

#include <iostream>

struct A {};
struct B {};

constexpr A aaa = {};
constexpr B bbb = {};

using A_type = decltype(aaa);
using B_type = decltype(bbb);

template <typename T>
void foo(T, A_type) { std::cout << "a"; }

template <typename T>
void foo(T, B_type) { std::cout << "b"; }

int main()
{
    foo(0, aaa);
    foo(0, bbb);
}
Run Code Online (Sandbox Code Playgroud)

但这个变体会产生相同的错误(不知道该怎么做):

template <typename T>
struct TypeWrapper {
    using type = T;
};

template <typename T>
void foo(T, typename TypeWrapper<decltype(aaa)>::type) { std::cout << "a"; }

template <typename T>
void foo(T, typename TypeWrapper<decltype(bbb)>::type) { std::cout << "b"; }
Run Code Online (Sandbox Code Playgroud)