AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
九韶内核 1.0.0.0
载入中...
搜索中...
未找到
SFINAE.hpp 文件参考

Defines commonly used SFINAE utils. 更多...

#include <type_traits>
SFINAE.hpp 的引用(Include)关系图:

命名空间

namespace  AMCAX
 AMCAX 内核提供的所有接口所在的命名空间。
 
namespace  AMCAX::Meshing
 AMCAX Meshing 模块提供的所有接口所在的命名空间。
 

宏定义

#define CLASS_HAS_FUNC(ClassName, FuncName)
 Check if a class has specified function.
 
#define CLASS_HAS_CONST_FUNC(ClassName, FuncName)
 Check if a class has specified const function.
 
#define CLASS_HAS_STATIC_FUNC(ClassName, FuncName)
 check if a class has specified function.
 
#define CLASS_HAS_TYPE(ClassName, TypeName)
 check if a class has specified type.
 
#define GET_TYPE_OTHERWISE_DEFAULT(ClassName, TypeName, DefaultType, Result)
 Check if a class has specified type then get the type, otherwise get the default type.
 
#define GET_TYPE_OTHERWISE_VOID(ClassName, TypeName, Result)
 Check if a class has specified type then get the type, otherwise get the void type.
 
#define CLASS_HAS_VALUE(ClassName, ValueName, Result)
 check if a class has specified value.
 
#define GET_VALUE_OTHERWISE_DEFAULT(ClassName, ValueType, ValueName, DefaultValue, Result)
 

详细描述

Defines commonly used SFINAE utils.

This file is part of AMCAX kernel.

宏定义说明

◆ CLASS_HAS_CONST_FUNC

#define CLASS_HAS_CONST_FUNC ( ClassName,
FuncName )
值:
template <typename... Args> \
class SFINAE_##ClassName##_has_##FuncName \
{ \
template <typename C, \
typename = decltype(std::declval<std::add_const_t<C>>() \
.FuncName(std::declval<Args>()...))> \
static std::true_type test(int); \
template <typename C> \
static std::false_type test(...); \
\
public: \
static constexpr bool value = decltype(test<ClassName>(0))::value; \
};

Check if a class has specified const function.

模板参数
ArgsParameter types passed to the function.
注解
You need to pass function parameters to this template by yourself.

◆ CLASS_HAS_FUNC

#define CLASS_HAS_FUNC ( ClassName,
FuncName )
值:
template <typename... Args> \
class SFINAE_##ClassName##_has_##FuncName \
{ \
template <typename C, typename = decltype(std::declval<C>().FuncName( \
std::declval<Args>()...))> \
static std::true_type test(int); \
template <typename C> \
static std::false_type test(...); \
\
public: \
static constexpr bool value = decltype(test<ClassName>(0))::value; \
};

Check if a class has specified function.

模板参数
ArgsParameter types passed to the function.
注解
You need to pass function parameters to this template by yourself.

◆ CLASS_HAS_STATIC_FUNC

#define CLASS_HAS_STATIC_FUNC ( ClassName,
FuncName )
值:
template <typename RetT, typename... Args> \
class SFINAE_##ClassName##_has_##FuncName \
{ \
template <typename F, F> \
struct helper \
{ \
}; \
template <typename C> \
static constexpr std::true_type \
test(helper<RetT (*)(Args...), C::FuncName> *); \
template <typename C> \
static constexpr std::false_type test(...); \
\
public: \
static constexpr bool value = decltype(test<ClassName>(nullptr))::value; \
};

check if a class has specified function.

A non-static member function receives an instance of the class as first parameter. So we need to explicitly declare the function type of "func". "typename F" is the type of function, "F" is the instance of function.

注解
You need to pass return type and paramters type to this template by yourself.

◆ CLASS_HAS_TYPE

#define CLASS_HAS_TYPE ( ClassName,
TypeName )
值:
class SFINAE_##ClassName##_has_##TypeName \
{ \
template <typename C> \
static constexpr std::true_type test(typename C::TypeName *); \
template <typename C> \
static constexpr std::false_type test(...); \
\
public: \
static constexpr bool value = decltype(test<ClassName>(nullptr))::value; \
};

check if a class has specified type.

◆ CLASS_HAS_VALUE

#define CLASS_HAS_VALUE ( ClassName,
ValueName,
Result )
值:
class SFINAE_##ClassName##_has_##ValueName \
{ \
template <typename C> \
static constexpr std::true_type test(typename decltype(C::ValueName) *); \
template <typename C> \
static constexpr std::false_type test(...); \
\
public: \
static constexpr bool value = decltype(test<ClassName>(nullptr))::value; \
}; \
static constexpr bool Result = SFINAE_##ClassName##_has_##ValueName::value;

check if a class has specified value.

◆ GET_TYPE_OTHERWISE_DEFAULT

#define GET_TYPE_OTHERWISE_DEFAULT ( ClassName,
TypeName,
DefaultType,
Result )
值:
class SFINAE_get_##TypeName##_from_##ClassName \
{ \
template <typename C> \
static constexpr auto test(typename C::TypeName *) -> \
typename C::TypeName; \
template <typename C> \
static constexpr auto test(...) -> DefaultType; \
\
public: \
typedef decltype(test<ClassName>(nullptr)) type; \
}; \
using Result = typename SFINAE_get_##TypeName##_from_##ClassName::type;

Check if a class has specified type then get the type, otherwise get the default type.

参数
ClassNameThe class where to find type.
TypeNameThe name of the type.
DefaultTypeIf doesn't find the type, the return DefaultType.
ResultFound result will be stored in Result.

◆ GET_TYPE_OTHERWISE_VOID

#define GET_TYPE_OTHERWISE_VOID ( ClassName,
TypeName,
Result )
值:
GET_TYPE_OTHERWISE_DEFAULT(ClassName, TypeName, void, Result)
#define GET_TYPE_OTHERWISE_DEFAULT(ClassName, TypeName, DefaultType, Result)
Check if a class has specified type then get the type, otherwise get the default type.
定义 SFINAE.hpp:100

Check if a class has specified type then get the type, otherwise get the void type.

参数
ClassNameThe class where to find type.
TypeNameThe name of the type.
ResultFound result will be stored in Result.

◆ GET_VALUE_OTHERWISE_DEFAULT

#define GET_VALUE_OTHERWISE_DEFAULT ( ClassName,
ValueType,
ValueName,
DefaultValue,
Result )
值:
class SFINAE_get_##ValueName##_from_##ClassName \
{ \
template <typename C> \
static constexpr ValueType test(decltype(C::ValueName) *) \
{ \
return C::ValueName; \
} \
template <typename C> \
static constexpr ValueType test(...) \
{ \
return DefaultValue; \
} \
\
public: \
static constexpr ValueType value = test<ClassName>(nullptr); \
}; \
static constexpr ValueType Result = \
SFINAE_get_##ValueName##_from_##ClassName::value;