首先,我在做什么
似乎
致力于所有
GCC/Clang/MSVC/icc/etc
,所以我的问题是;
这是偶然的,还是标准要求允许的?
从某种意义上说,它似乎是东西的逻辑扩展,但另一方面,语法看起来很奇怪,我担心自己会陷入沉思
depending-on-bugs
领土:
#include <type_traits>
template <int, bool>
void Bar();
template <int i>
struct A {
struct T : std::true_type {};
static void Foo() { Bar<i, T::value>(); }
};
// The normal way to do thing:
template <> struct A<1>::T : std::false_type {};
// But this also seems to work despite looking very odd:
using A3 = A<3>;
template <> struct A3::T : std::false_type {};
void Go() {
A<0>::Foo(); // Calls Bar<0, true>()
A<1>::Foo(); // Calls Bar<1, false>()
A<2>::Foo(); // Calls Bar<2, true>()
A<3>::Foo(); // Calls Bar<3, false>()
}