VLink  2.0.0
A high-performance communication middleware
traits.h File Reference

Compile-time type-trait helpers used across the VLink codebase. More...

#include <atomic>
#include <memory>
#include <type_traits>
Include dependency graph for traits.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  vlink::Traits::EmptyType
 Empty tag type used wherever a type parameter must be supplied but carries no payload. More...
 
struct  vlink::Traits::ExpectFalse< T >
 Type trait that always derives from std::false_type for any T. More...
 
struct  vlink::Traits::Callable< T, typename >
 Detects whether T can be invoked with no arguments. More...
 
struct  vlink::Traits::Callable< T, std::void_t< decltype(std::declval< T >()())> >
 
struct  vlink::Traits::Assignable< OT, T, typename >
 Detects whether a value of type T can be assigned to an instance of OT. More...
 
struct  vlink::Traits::Assignable< OT, T, std::void_t< decltype(std::declval< OT & >()=std::declval< T >())> >
 
struct  vlink::Traits::EqualityComparable< OT, T, typename >
 Detects whether OT supports operator== with T. More...
 
struct  vlink::Traits::EqualityComparable< OT, T, std::void_t< decltype(std::declval< OT >()==std::declval< T >())> >
 
struct  vlink::Traits::GreaterComparable< OT, T, typename >
 Detects whether OT supports both operator< and operator> with T. More...
 
struct  vlink::Traits::GreaterComparable< OT, T, std::void_t< decltype(std::declval< OT & >()< std::declval< T >()), decltype(std::declval< OT & >() > std::declval< T & >())> >
 
struct  vlink::Traits::Operatorable< OT, T, typename >
 Detects whether OT supports stream insertion (<<) and extraction (>>) with T. More...
 
struct  vlink::Traits::Operatorable< OT, T, std::void_t< decltype(std::declval< OT & >()<< std::declval< T >()), decltype(std::declval< OT & >() >> std::declval< T & >())> >
 
struct  vlink::Traits::IsAtomic< T >
 Detects whether T is a std::atomic specialisation. More...
 
struct  vlink::Traits::IsAtomic< std::atomic< T > >
 
struct  vlink::Traits::IsSharedPtr< T, typename >
 Detects whether T is (or derives from) a std::shared_ptr specialisation. More...
 
struct  vlink::Traits::IsSharedPtr< T, std::void_t< typename T::element_type > >
 
struct  vlink::Traits::RemoveSharedPtr< T, bool >
 Removes a single std::shared_ptr wrapper from T, leaving non-pointer types unchanged. More...
 
struct  vlink::Traits::RemoveSharedPtr< T, true >
 

Namespaces

 
 

Macros

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

Detailed Description

Compile-time type-trait helpers used across the VLink codebase.

vlink::Traits collects a small set of self-contained template meta-functions that extend the C++ standard <type_traits>. Every helper follows the standard pattern of either inheriting from std::true_type / std::false_type or returning a bool from a constexpr function. The macro VLINK_HAS_MEMBER ties into has_member to detect named data or function members at compile time.

Trait reference:

Helper What it detects
EmptyType An empty tag type used as a no-op placeholder.
ExpectFalse<T> Always std::false_type; used for dependent static_assert.
Callable<T> T can be invoked with no arguments.
Assignable<OT,T> OT can be assigned a value of type T.
EqualityComparable OT supports operator== with T.
GreaterComparable OT supports both operator< and operator> with T.
Operatorable<OT,T> OT supports stream insertion and extraction with T.
IsAtomic<T> T is a std::atomic specialisation.
IsSharedPtr<T> T is a std::shared_ptr (or derived) specialisation.
RemoveSharedPtr<T> Removes a single std::shared_ptr wrapper from T.
has_member<T>(f) Compile-time member-access probe used by VLINK_HAS_MEMBER.
is_non_char_ptr<T>() T decays to a pointer other than char*.
is_integer<T>() T is an integer excluding bool and the char variants.
is_floating<T>() T is a floating-point type.
Example
struct Foo { int bar; void baz() {} };
static_assert( VLINK_HAS_MEMBER(Foo, bar));
static_assert(!VLINK_HAS_MEMBER(Foo, qux));
static_assert( VLINK_HAS_MEMBER(Foo, baz()));
static_assert(vlink::Traits::Callable<decltype([] {})>::value);
static_assert(vlink::Traits::IsAtomic<std::atomic<int>>::value);
#define VLINK_HAS_MEMBER(T, member)
Macro Definitions.
Definition: traits.h:316

Macro Definition Documentation

◆ 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.

Compile-time check that T has an accessible member named member.

Expands to a constexpr boolean expression. Use call syntax (member()) to probe for a member function rather than a data member. Internally delegates to vlink::Traits::has_member.

Parameters
TType to inspect.
memberMember name (or member() for a callable probe).
Example
struct Foo { int bar; void baz() {} };
static_assert( VLINK_HAS_MEMBER(Foo, bar));
static_assert(!VLINK_HAS_MEMBER(Foo, qux));
static_assert( VLINK_HAS_MEMBER(Foo, baz()));