sfinae.h
Go to the documentation of this file.
// -*- C++ -*- Substitution Failure Is Not An Error
#ifndef WIBBLE_SFINAE_H
#define WIBBLE_SFINAE_H
namespace wibble {
struct Unit {
bool operator<( Unit ) const { return false; }
bool operator==( Unit ) const { return true; }
};
struct TTrue {
static const bool value = true;
};
struct TFalse {
static const bool value = false;
};
// small SFINAE utilities, we probably prefer to avoid full weight of boost here
template< typename A, typename B >
struct TSame {
static const bool value = false;
};
template< typename A >
struct TSame< A, A > {
static const bool value = true;
};
template< bool, bool, bool = true, bool = true, bool = true >
struct TAndC {
static const bool value = false;
};
template<>
struct TAndC< true, true, true, true, true > {
static const bool value = true;
};
template< typename A, typename B,
typename C = TTrue, typename D = TTrue, typename E = TTrue >
struct TAnd : TAndC< A::value, B::value, C::value, D::value, E::value > {};
template< bool, bool, bool = false, bool = false, bool = false >
struct TOrC {
static const bool value = true;
};
template<>
struct TOrC< false, false, false, false, false > {
static const bool value = false;
};
template< typename A, typename B,
typename C = TFalse, typename D = TFalse, typename E = TFalse >
struct TOr : TOrC< A::value, B::value, C::value, D::value, E::value > {};
/* template< typename T >
struct IsT {
static const bool value = true;
}; */
template< bool a > struct TNotC {
static const bool value = !a;
};
template< typename T > struct TNot : TNotC< T::value > {};
template< bool a, bool b >
struct TImplyC : TNot< TAndC< a, TNotC< b >::value > > {};
template< typename A, typename B >
struct TImply : TImplyC< A::value, B::value > {};
template< bool, typename T = Unit >
struct EnableIfC {};
template< typename Type >
struct EnableIfC< true, Type > { typedef Type T; };
template< bool, typename T = Unit >
struct DisableIfC {};
template< typename Type >
struct DisableIfC< false, Type > { typedef Type T; };
template< typename X, typename T = Unit >
struct EnableIf : EnableIfC< X::value, T > {};
template< typename X, typename T = Unit >
struct DisableIf : DisableIfC< X::value, T > {};
template< typename A, typename B >
struct TPair {
typedef A First;
typedef B Second;
};
struct Preferred {};
struct NotPreferred { NotPreferred( Preferred ) {} };
}
#endif
wibble
Definition: amorph.h:17
wibble::DisableIfC< false, Type >::T
Type T
Definition: sfinae.h:87
wibble::DisableIfC
Definition: sfinae.h:84
wibble::DisableIf
Definition: sfinae.h:93
wibble::EnableIfC< true, Type >::T
Type T
Definition: sfinae.h:81
wibble::EnableIfC
Definition: sfinae.h:78
wibble::EnableIf
Definition: sfinae.h:90
wibble::NotPreferred
Definition: sfinae.h:102
wibble::NotPreferred::NotPreferred
NotPreferred(Preferred)
Definition: sfinae.h:102
wibble::Preferred
Definition: sfinae.h:101
wibble::TAndC
Definition: sfinae.h:33
wibble::TAndC::value
static const bool value
Definition: sfinae.h:34
wibble::TAnd
Definition: sfinae.h:44
wibble::TFalse
Definition: sfinae.h:17
wibble::TFalse::value
static const bool value
Definition: sfinae.h:18
wibble::TImplyC
Definition: sfinae.h:72
wibble::TImply
Definition: sfinae.h:75
wibble::TNotC
Definition: sfinae.h:65
wibble::TNotC::value
static const bool value
Definition: sfinae.h:66
wibble::TNot
Definition: sfinae.h:69
wibble::TOrC
Definition: sfinae.h:47
wibble::TOrC::value
static const bool value
Definition: sfinae.h:48
wibble::TOr
Definition: sfinae.h:58
wibble::TPair
Definition: sfinae.h:96
wibble::TPair::First
A First
Definition: sfinae.h:97
wibble::TPair::Second
B Second
Definition: sfinae.h:98
wibble::TSame
Definition: sfinae.h:23
wibble::TSame::value
static const bool value
Definition: sfinae.h:24
wibble::TTrue
Definition: sfinae.h:13
wibble::TTrue::value
static const bool value
Definition: sfinae.h:14
wibble::Unit
Definition: sfinae.h:8
wibble::Unit::operator==
bool operator==(Unit) const
Definition: sfinae.h:10
wibble::Unit::operator<
bool operator<(Unit) const
Definition: sfinae.h:9