cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::logger::has_ostream_method< T > Struct Template Reference

检查类型是否具有ostream方法的类型特征 / Type trait to check if a type has an ostream method More...

#include <thread_logger.hpp>

Static Public Member Functions

template<typename U >
static auto test (int) -> std::is_same< decltype(std::declval< U >().operator<<(std::declval< std::ostream & >())), std::ostream & >
 
template<typename >
static auto test (...) -> std::false_type
 

Static Public Attributes

static constexpr bool value = decltype(test<T>(0))::value
 

Detailed Description

template<typename T>
struct toolbox::logger::has_ostream_method< T >

检查类型是否具有ostream方法的类型特征 / Type trait to check if a type has an ostream method

此模板检查类型是否具有可以接受ostream引用的成员operator<<方法 / This template checks if a type has a member operator<< method that can accept an ostream reference

Template Parameters
T要检查ostream方法的类型 / The type to check for ostream method
struct MyType {
std::ostream& operator<<(std::ostream& os) const { return os; }
};
static_assert(has_ostream_method<MyType>::value, "MyType has ostream
method");
static constexpr bool value
Definition thread_logger.hpp:172

Member Function Documentation

◆ test() [1/2]

template<typename T >
template<typename >
static auto toolbox::logger::has_ostream_method< T >::test (   ...) -> std::false_type
static

◆ test() [2/2]

template<typename T >
template<typename U >
static auto toolbox::logger::has_ostream_method< T >::test ( int  ) -> std::is_same< decltype(std::declval< U >().operator<<(std::declval< std::ostream & >())), std::ostream & >
static

Member Data Documentation

◆ value

template<typename T >
constexpr bool toolbox::logger::has_ostream_method< T >::value = decltype(test<T>(0))::value
staticconstexpr

The documentation for this struct was generated from the following file: