How can I detect if a type can be streamed to an std::ostream?

前端 未结 6 1552
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 00:41

I\'m trying to write a type trait to detect if a type has overloaded operator<<() suitable to use to an output stream.

I\'m missing something because I\'m alwa

6条回答
  •  粉色の甜心
    2020-12-13 01:04

    And to test for '>>' operator:

    template class is_istreamable
    {
        template
        static auto test (int) -> decltype (std::declval() >> std::declval(), std::true_type ());
    
        template
        static auto test (...) -> std::false_type;
    
    public:
    
        static const bool value = decltype (test (0))::value;
    };
    

提交回复
热议问题