vendredi 28 septembre 2018

MSVC's (seem not perfect) support for constexpr

I am making the naive wheel of type traits's is_base_of. And Here's a minimal demo about my implementation(didn't consider robustness, is_class...).

#include <type_traits>
#include <cstdint>
struct A
{

};
struct B : A
{

};
template
<typename T, typename U>
struct IsBaseOf {
    constexpr static bool Test(T* t)
    {
        return true;
    }

    constexpr static bool Test(...)
    {
        return false;
    }

    constexpr static bool value = IsBaseOf<T,U>::Test(static_cast<U*>(nullptr));
};
int main()
{
    static_assert(IsBaseOf<A, B>::value, "Pass");
}

This demo can be compiled by gcc/clang but cannot be compiled by MSVC. http://rextester.com/ATOC6638 http://rextester.com/IWU81465

When i type it on my laptop's Visual Studio 2015(with update patch 3). It cannot be compiled either, the IDE reminds me that "expression must have constant value" before compiling.

So I wonder how's MSVC support for constexpr, or is my code wrong?

Aucun commentaire:

Enregistrer un commentaire