VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
traits.h 文件参考

Compile-time type-trait utilities used internally by VLink. 更多...

#include <atomic>
#include <memory>
#include <type_traits>
traits.h 的引用(Include)关系图:
此图展示该文件被哪些文件直接或间接地引用了:

浏览该文件的源代码.

 An empty tag type used as a neutral placeholder in template meta-programming. 更多...
 A type trait that always evaluates to std::false_type. 更多...
 Detects whether type T is callable with no arguments. 更多...
 Detects whether an object of type OT can be assigned a value of type T. 更多...
 Detects whether OT supports the == operator with T. 更多...
 Detects whether OT supports both < and > operators with T. 更多...
 Detects whether OT supports << and >> stream operators with T. 更多...
 Detects whether type T is a std::atomic specialization. 更多...
 Detects whether type T is a std::shared_ptr specialization. 更多...
 Strips std::shared_ptr to obtain the underlying element type. 更多...

命名空间

宏定义

#define VLINK_HAS_MEMBER(T, member)
 Macro Definitions

详细描述

Compile-time type-trait utilities used internally by VLink.

The vlink::Traits namespace collects a set of small, self-contained template meta-programming helpers that are used throughout the VLink codebase to detect type properties at compile time. They follow the same conventions as the C++ standard library <type_traits> header.

All helpers are either:

  • Struct templates inheriting from std::true_type / std::false_type, or
  • constexpr functions returning bool.
Helper Description
EmptyType An empty tag type used as a placeholder
ExpectFalse Always evaluates to std::false_type (useful in static_assert)
Callable Detects whether T is callable with no arguments
Assignable Detects whether OT is assignable from T
EqualityComparable Detects whether OT supports == with T
GreaterComparable Detects whether OT supports < and > with T
Operatorable Detects whether OT supports << and >> stream operators with T
IsAtomic Detects whether T is a std::atomic specialization
IsSharedPtr Detects whether T is a std::shared_ptr specialization
RemoveSharedPtr Strips the std::shared_ptr wrapper to obtain the element type
has_member Runtime-style SFINAE check for a named member
is_non_char_ptr True when T decays to a non-char pointer
is_integer True for integer types excluding bool, char, and signed/unsigned char
is_floating True for floating-point types
注解
These utilities live in the vlink::Traits namespace (note the capital T). VLINK_HAS_MEMBER is the corresponding macro wrapper for has_member.
Example: checking for a member at compile time
struct Foo { void bar() {} };
struct Baz {};
// Using the macro (preferred for member name checks):
static_assert(VLINK_HAS_MEMBER(Foo, bar));
static_assert(!VLINK_HAS_MEMBER(Baz, bar));
// Using the template directly:
static_assert(vlink::Traits::Callable<std::function<void()>>::value);
#define VLINK_HAS_MEMBER(T, member)
Macro Definitions
定义 traits.h:350

宏定义说明

◆ VLINK_HAS_MEMBER

#define VLINK_HAS_MEMBER ( T,
member )
值:
vlink::Traits::has_member<T>([](auto&& obj) -> decltype((void)(obj.member), 0) { return 0; })

Macro Definitions

Checks at compile time whether type T has an accessible member named member.

Expands to a constexpr boolean expression (true/false) evaluated at compile time. Internally delegates to vlink::Traits::has_member.

参数
TThe type to inspect.
memberThe unquoted member name to look for.
Example
struct Foo { int bar; };
static_assert(VLINK_HAS_MEMBER(Foo, bar));
static_assert(!VLINK_HAS_MEMBER(Foo, baz));