LoginSignup
0
0

More than 3 years have passed since last update.

msvcでテンプレートテンプレートのバグ

Last updated at Posted at 2019-05-13

備忘録も兼ねて

Visual Studioさんいつも変なバグありません?

テンプレートテンプレートを使った次のコード

#include <type_traits>

template <template <class...>class Temp, class Ins>
struct is_template_instance : std::false_type {};

template <template <class...>class Temp, class ...Args>
struct is_template_instance<Temp, Temp<Args...>> : std::true_type {};

template <template <class...>class Temp, class Ins>
inline constexpr bool is_template_instance_v = is_template_instance<Temp, Ins>::value;

template <class T>
struct Foo {
    template <class U>
    static constexpr bool is_foo = is_template_instance<Foo, U>::value;
};

template <class T>
struct Bar {
    template <class U>
    static constexpr bool is_bar = is_template_instance_v<Bar, U>;
};

static_assert(Foo<int>::is_foo<Foo<double>>);

static_assert(Bar<int>::is_bar<Bar<double>>);

visual studio 2019 ではコンパイルできない

Fooの方はstatic_assertで失敗していて
Barの方はis_template_instance_v<Bar, U>のBarが引数を省略したクラスとして扱わてしまっているみたい

コミュニティに回避策が上がってた
https://developercommunity.visualstudio.com/content/problem/558979/c-template-template-not-recognized-as-class-templa.html

呼び出し側をちょっといじるとコンパイル通るみたい

is_template_instance_v<::Foo, U>;

なんでこれでFooもBarもコンパイル通るようになるんだ...?(どういうバグなんだ...)

ただ、名前空間内にあると(その場合の方が多いような気がするけど)

is_template_instance_v<ns::Foo, U>;

みたいに長くなってしまう。MSさんはよ直して...

余談?

投稿直後にQiitaのタグフィード見てみたら投稿時刻が負にになってた
rapture_20190513124501.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0