• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    class template
    <type_traits>

    std::is_void

    namespace std {
      template <class T>
      struct is_void;
    
      template <class T>
      inline constexpr bool is_void_v = is_void<T>::value; // C++17
    }
    

    概要

    Tvoidか調べる

    効果

    is_voidは、型Tvoid(cv修飾を許容する)であればtrue_typeから派生し、そうでなければfalse_typeから派生する。

    #include <type_traits>
    
    static_assert(std::is_void<void>::value == true, "value == true, void is void");
    static_assert(std::is_same<std::is_void<void>::value_type, bool>::value, "value_type == bool");
    static_assert(std::is_same<std::is_void<void>::type, std::true_type>::value, "type == true_type");
    static_assert(std::is_void<void>() == true, "is_void<void>() == true");
    
    static_assert(std::is_void<int>::value == false, "value == false, int is not void");
    static_assert(std::is_same<std::is_void<int>::value_type, bool>::value, "value_type == bool");
    static_assert(std::is_same<std::is_void<int>::type, std::false_type>::value, "type == false_type");
    static_assert(std::is_void<int>() == false, "is_void<int>() == false");
    
    static_assert(std::is_void<const void>::value == true, "const void is void");
    static_assert(std::is_void<volatile void>::value == true, "volatile void is void");
    static_assert(std::is_void<const volatile void>::value == true, "const volatile void is void");
    
    static_assert(std::is_void<void*>::value == false, "a pointer to void is not void");
    static_assert(std::is_void<void ()>::value == false, "a function returning void is not void");
    
    int main(){}
    

    出力

    バージョン

    言語

    • C++11

    処理系

    • GCC: 4.3.4 , 4.5.3 , 4.6.1
    • Visual C++: 2008 (std::tr1) , 2010 , 2012 , 2013 , 2015

    備考

    上の例でコンパイラによってはエラーになる。GCC 4.3.4, 4.5.3, Visual C++ 2010 は integral_constantoperator bool() を持っていないためエラーになる。

    参照