タグ付けされた質問 「typetraits」

5
「is_base_of」はどのように機能しますか?
次のコードはどのように機能しますか? typedef char (&yes)[1]; typedef char (&no)[2]; template <typename B, typename D> struct Host { operator B*() const; operator D*(); }; template <typename B, typename D> struct is_base_of { template <typename T> static yes check(D*, T); static no check(B*, int); static const bool value = sizeof(check(Host<B,D>(), int())) == sizeof(yes); }; …



1
std :: is_constructibleがプライベートコンストラクターに矛盾した値を返す
std::is_constructibleがプライベートコンストラクターを処理するルールは何ですか?次のコードがあるとします: #include <iostream> class Class { private: Class() { } }; template <typename T> class Test { public: static void test() { std::cout //<< std::is_constructible<Class>::value << std::is_constructible<T>::value << std::endl; } }; int main() { Test<Class>::test(); } これは0(ideone)を出力しTます。つまり、デフォルトでは構築できません。 コメント行のコメントを外すと、出力されます11(ideone)。そのため、突然Tデフォルトで構築可能になりました。 私は両方の結果をサポートする理由を見つけることができましたが、コメント行を含めると2番目の結果がどのように変わるかわかりません。これはどういうわけかUBを呼び出していますか?これはコンパイラのバグですか?それともstd::is_constructible本当に矛盾していますか?
13 c++  typetraits 

1
gccのis_nothrow_constructibleの実装でstatic_castが必要なのはなぜですか?
GCC実装から取得した、type_traitsなぜstatic_castここで必要なのですか? template <typename _Tp, typename... _Args> struct __is_nt_constructible_impl : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))> {}; template <typename _Tp, typename _Arg> struct __is_nt_constructible_impl<_Tp, _Arg> : public integral_constant<bool, // Why is `static_cast` needed here? noexcept(static_cast<_Tp>(declval<_Arg>()))> {};

3
次の場合に依存型にtypenameを使用する必要がないのはなぜですか?
型の参照の削除については、ここで読んでいます。 次の例を示します。 #include <iostream> // std::cout #include <type_traits> // std::is_same template<class T1, class T2> void print_is_same() { std::cout << std::is_same<T1, T2>() << '\n'; } int main() { std::cout << std::boolalpha; print_is_same<int, int>(); print_is_same<int, int &>(); print_is_same<int, int &&>(); print_is_same<int, std::remove_reference<int>::type>(); // Why not typename std::remove_reference<int>::type ? print_is_same<int, std::remove_reference<int &>::type>();// Why …

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.