Pytania otagowane jako typetraits

5
Jak działa „is_base_of”?
Jak działa poniższy kod? 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())) …



1
std :: is_constructible zwraca niespójną wartość dla prywatnego konstruktora
Jakie są reguły, według których std::is_constructibleobsługuje się konstruktorów prywatnych? Biorąc pod uwagę następujący kod: #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(); } To …
13 c++  typetraits 

1
Dlaczego static_cast jest potrzebny w implementacji gcc programu is_nothrow_constructible?
type_traitsDlaczego wzięto z wdrożenia GCC, dlaczego jest static_casttutaj potrzebny? 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
Dlaczego nie jest wymagane używanie nazwy typu dla typów zależnych w następującym przypadku?
Czytałem o usuwaniu odwołania do typu tutaj . Daje następujący przykład: #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>(); // …
Korzystając z naszej strony potwierdzasz, że przeczytałeś(-aś) i rozumiesz nasze zasady używania plików cookie i zasady ochrony prywatności.
Licensed under cc by-sa 3.0 with attribution required.