Remove tcg_sfinae.h

This commit is contained in:
Tact Yoshida 2019-04-12 23:47:57 +09:00
parent 91a93e2575
commit f87d668578
4 changed files with 4 additions and 297 deletions

View file

@ -5,7 +5,6 @@
// tcg includes
#include "traits.h"
#include "sfinae.h"
#include "macros.h"
// STD includes
@ -90,7 +89,7 @@ inline bool areNear(Scalar a, Scalar b, Scalar tolerance) {
//-------------------------------------------------------------------------------------------
template <typename Scalar>
inline typename tcg::disable_if<tcg::is_floating_point<Scalar>::value,
inline typename std::enable_if<!tcg::is_floating_point<Scalar>::value,
Scalar>::type
mod(Scalar val, Scalar mod) {
Scalar m = val % mod;
@ -99,7 +98,7 @@ mod(Scalar val, Scalar mod) {
template <typename Scalar>
inline
typename tcg::enable_if<tcg::is_floating_point<Scalar>::value, Scalar>::type
typename std::enable_if<tcg::is_floating_point<Scalar>::value, Scalar>::type
mod(Scalar val, Scalar mod) {
Scalar m = fmod(val, mod);
return (m >= 0) ? m : m + mod;
@ -138,7 +137,7 @@ inline Scalar modShift(Scalar val1, Scalar val2, Scalar a, Scalar b) {
\return Integral quotient of the division of \p val by \p d.
*/
template <typename Scalar>
inline typename tcg::disable_if<tcg::is_floating_point<Scalar>::value,
inline typename std::enable_if<!tcg::is_floating_point<Scalar>::value,
Scalar>::type
div(Scalar val, Scalar d) {
TCG_STATIC_ASSERT(-3 / 5 == 0);
@ -153,7 +152,7 @@ div(Scalar val, Scalar d) {
*/
template <typename Scalar>
inline
typename tcg::enable_if<tcg::is_floating_point<Scalar>::value, Scalar>::type
typename std::enable_if<tcg::is_floating_point<Scalar>::value, Scalar>::type
div(Scalar val, Scalar d) {
return std::floor(val / d);
}

View file

@ -1,101 +0,0 @@
#pragma once
#ifndef TCG_SFINAE_H
#define TCG_SFINAE_H
/*!
\file sfinae.h
\brief Contains template metafunctions that can be used to enable or
disable template class members.
\details SFINAE (Substitution Failure Is Not An Error) is a C++ \a feature
that allows the compiler to silently discard failures in template
function instantiations during function overload resolution.
*/
#if defined(__APPLE_CC__)
#include <type_traits>
#endif
namespace tcg {
template <typename X, typename Y>
struct type_match {
enum { value = false };
};
template <typename X>
struct type_match<X, X> {
enum { value = true };
};
//------------------------------------------------------------------------
template <typename X, typename Y>
struct type_mismatch {
enum { value = true };
};
template <typename X>
struct type_mismatch<X, X> {
enum { value = false };
};
//========================================================================
template <typename T, typename B>
struct enable_if_exists {
typedef B type;
};
//========================================================================
template <bool, typename T = void>
struct enable_if {};
template <typename T>
struct enable_if<true, T> {
typedef T type;
};
//========================================================================
template <bool, typename T = void>
struct disable_if {
typedef T type;
};
template <typename T>
struct disable_if<true, T> {};
//========================================================================
template <bool, typename TrueT, typename FalseT = void>
struct choose_if;
template <typename TrueT, typename FalseT>
struct choose_if<true, TrueT, FalseT> {
typedef TrueT type;
};
template <typename TrueT, typename FalseT>
struct choose_if<false, TrueT, FalseT> {
typedef FalseT type;
};
//========================================================================
template <typename T, typename MatchT, typename NotMatchedT = void>
struct choose_if_match {
typedef NotMatchedT type;
};
template <typename MatchT, typename NotMatchedT>
struct choose_if_match<MatchT, MatchT, NotMatchedT> {
typedef MatchT type;
};
} // namespace tcg
#endif // TCG_SFINAE_H

View file

@ -1,3 +0,0 @@
#pragma once
#include "sfinae.h"

View file

@ -3,9 +3,6 @@
#ifndef TCG_TRAITS_H
#define TCG_TRAITS_H
// tcg includes
#include "sfinae.h"
// STD includes
#include <iterator>
@ -78,170 +75,6 @@ struct remove_cref {
typedef typename remove_const<typename remove_ref<T>::type>::type type;
};
//****************************************************************************
// TCG traits for function types
//****************************************************************************
template <typename Func>
class function_traits {
template <typename F, bool>
struct result;
template <typename F>
struct result<F, true> {
typedef typename F::result_type type;
};
template <typename F>
struct result<F, false> {
typedef struct { } type; };
template <typename Q>
static typename enable_if_exists<typename Q::result_type, char>::type
result_fun(Q *);
static double result_fun(...);
template <typename F, bool>
struct argument;
template <typename F>
struct argument<F, true> {
typedef typename F::argument_type type;
};
template <typename F>
struct argument<F, false> {
typedef void type;
};
template <typename Q>
static typename enable_if_exists<typename Q::argument_type, char>::type
argument_fun(Q *);
static double argument_fun(...);
template <typename F, bool>
struct first_arg;
template <typename F>
struct first_arg<F, true> {
typedef typename F::first_argument_type type;
};
template <typename F>
struct first_arg<F, false> {
typedef void type;
};
template <typename Q>
static typename enable_if_exists<typename Q::first_argument_type, char>::type
first_arg_fun(Q *);
static double first_arg_fun(...);
template <typename F, bool>
struct second_arg;
template <typename F>
struct second_arg<F, true> {
typedef typename F::second_argument_type type;
};
template <typename F>
struct second_arg<F, false> {
typedef void type;
};
template <typename Q>
static typename enable_if_exists<typename Q::second_argument_type, char>::type
second_arg_fun(Q *);
static double second_arg_fun(...);
public:
enum {
has_result =
(sizeof(result_fun(typename tcg::traits<Func>::pointer_type())) ==
sizeof(char)),
has_argument =
(sizeof(argument_fun(typename tcg::traits<Func>::pointer_type())) ==
sizeof(char)),
has_first_arg =
(sizeof(first_arg_fun(typename tcg::traits<Func>::pointer_type())) ==
sizeof(char)),
has_second_arg =
(sizeof(second_arg_fun(typename tcg::traits<Func>::pointer_type())) ==
sizeof(char))
};
typedef typename result<Func, has_result>::type ret_type;
typedef typename argument<Func, has_argument>::type arg_type;
typedef typename first_arg<Func, has_first_arg>::type arg1_type;
typedef typename second_arg<Func, has_second_arg>::type arg2_type;
};
//-----------------------------------------------------------------------
template <typename Ret>
struct function_traits<Ret()> {
enum {
has_result = true,
has_argument = false,
has_first_arg = false,
has_second_arg = false
};
typedef Ret ret_type;
typedef void arg_type;
typedef void arg1_type;
typedef void arg2_type;
};
template <typename Ret>
struct function_traits<Ret (*)()> : public function_traits<Ret()> {};
template <typename Ret>
struct function_traits<Ret (&)()> : public function_traits<Ret()> {};
//-----------------------------------------------------------------------
template <typename Ret, typename Arg>
struct function_traits<Ret(Arg)> {
enum {
has_result = true,
has_argument = true,
has_first_arg = false,
has_second_arg = false
};
typedef Ret ret_type;
typedef Arg arg_type;
typedef void arg1_type;
typedef void arg2_type;
};
template <typename Ret, typename Arg>
struct function_traits<Ret (*)(Arg)> : public function_traits<Ret(Arg)> {};
template <typename Ret, typename Arg>
struct function_traits<Ret (&)(Arg)> : public function_traits<Ret(Arg)> {};
//-----------------------------------------------------------------------
template <typename Ret, typename Arg1, typename Arg2>
struct function_traits<Ret(Arg1, Arg2)> {
enum { has_result = true, has_first_arg = true, has_second_arg = true };
typedef Ret ret_type;
typedef Arg1 arg1_type;
typedef Arg2 arg2_type;
};
template <typename Ret, typename Arg1, typename Arg2>
struct function_traits<Ret (*)(Arg1, Arg2)>
: public function_traits<Ret(Arg1, Arg2)> {};
template <typename Ret, typename Arg1, typename Arg2>
struct function_traits<Ret (&)(Arg1, Arg2)>
: public function_traits<Ret(Arg1, Arg2)> {};
//******************************************************************************
// TCG traits for output container readers
//******************************************************************************
@ -282,27 +115,6 @@ struct is_floating_point<long double> {
enum { value = true };
};
//-----------------------------------------------------------------------
template <typename T>
struct is_function {
enum { value = function_traits<T>::has_result };
};
template <typename T>
struct is_functor {
template <typename Q>
static typename enable_if_exists<typename Q::result_type, char>::type result(
Q *);
static double result(...);
enum {
value = (sizeof(result(typename tcg::traits<T>::pointer_type())) ==
sizeof(char))
};
};
} // namespace tcg
#endif // TCG_TRAITS_H