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

检查类型是否具有流插入运算符(<<)的类型特征 / Type trait to check if a type has stream insertion operator (<<) More...

#include <thread_logger.hpp>

Static Public Member Functions

template<typename U >
static auto test (int) -> std::is_same< decltype(std::declval< std::ostream & >()<< std::declval< const U & >()), 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_stream_operator< T >

检查类型是否具有流插入运算符(<<)的类型特征 / Type trait to check if a type has stream insertion operator (<<)

此模板检查类型是否可以使用流插入运算符插入到ostream中 / This template checks if a type can be inserted into an ostream using the stream insertion operator

Template Parameters
T要检查流插入能力的类型 / The type to check for stream insertion capability
// 检查int是否具有流运算符 / Check if int has stream operator
static_assert(has_stream_operator<int>::value, "int has stream operator");
// 检查自定义类型是否具有流运算符 / Check if custom type has stream operator
struct MyType {};
static_assert(!has_stream_operator<MyType>::value, "MyType lacks stream
operator");
检查类型是否具有流插入运算符(<<)的类型特征 / Type trait to check if a type has stream insertion operator (<<)
Definition thread_logger.hpp:113

Member Function Documentation

◆ test() [1/2]

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

◆ test() [2/2]

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

Member Data Documentation

◆ value

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

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