Use C++14 std::conditional_t (instead of custom IF template)

time-shift
Sébastien Villemot 2019-01-09 17:26:28 +01:00
parent 922014c2fa
commit 38c24347ff
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 17 additions and 40 deletions

View File

@ -41,6 +41,7 @@
#include <dynlapack.h>
#include <cmath>
#include <type_traits>
#define TYPENAME typename
@ -69,35 +70,23 @@ class UnfoldedZXContainer;
class FoldedGXContainer;
class UnfoldedGXContainer;
template<bool condition, class Then, class Else>
struct IF
{
using RET = Then;
};
template<class Then, class Else>
struct IF<false, Then, Else>
{
using RET = Else;
};
template <int type>
class ctraits
{
public:
enum { fold, unfold };
using Ttensor = TYPENAME IF<type == fold, FGSTensor, UGSTensor>::RET;
using Ttensym = TYPENAME IF<type == fold, FFSTensor, UFSTensor>::RET;
using Tg = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
using Tgs = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
using Tgss = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
using TG = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
using TZstack = TYPENAME IF<type == fold, FoldedZContainer, UnfoldedZContainer>::RET;
using TGstack = TYPENAME IF<type == fold, FoldedGContainer, UnfoldedGContainer>::RET;
using Tm = TYPENAME IF<type == fold, FNormalMoments, UNormalMoments>::RET;
using Tpol = TYPENAME IF<type == fold, FTensorPolynomial, UTensorPolynomial>::RET;
using TZXstack = TYPENAME IF<type == fold, FoldedZXContainer, UnfoldedZXContainer>::RET;
using TGXstack = TYPENAME IF<type == fold, FoldedGXContainer, UnfoldedGXContainer>::RET;
using Ttensor = std::conditional_t<type == fold, FGSTensor, UGSTensor>;
using Ttensym = std::conditional_t<type == fold, FFSTensor, UFSTensor>;
using Tg = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
using Tgs = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
using Tgss = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
using TG = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
using TZstack = std::conditional_t<type == fold, FoldedZContainer, UnfoldedZContainer>;
using TGstack = std::conditional_t<type == fold, FoldedGContainer, UnfoldedGContainer>;
using Tm = std::conditional_t<type == fold, FNormalMoments, UNormalMoments>;
using Tpol = std::conditional_t<type == fold, FTensorPolynomial, UTensorPolynomial>;
using TZXstack = std::conditional_t<type == fold, FoldedZXContainer, UnfoldedZXContainer>;
using TGXstack = std::conditional_t<type == fold, FoldedGXContainer, UnfoldedGXContainer>;
};
/* The |PartitionY| class defines the partitioning of state variables

View File

@ -68,6 +68,7 @@
#include <cstdio>
#include <list>
#include <map>
#include <type_traits>
namespace sthread
{
@ -76,19 +77,6 @@ namespace sthread
class Empty
{
};
// classical IF template
/* Here is the classical IF template. */
template<bool condition, class Then, class Else>
struct IF
{
using RET = Then;
};
template<class Then, class Else>
struct IF<false, Then, Else>
{
using RET = Else;
};
enum { posix, empty};
@ -103,7 +91,7 @@ namespace sthread
template <int thread_impl>
struct thread_traits
{
using _Tthread = typename IF<thread_impl == posix, pthread_t, Empty>::RET;
using _Tthread = std::conditional_t<thread_impl == posix, pthread_t, Empty>;
using _Ctype = thread<0>;
using _Dtype = detach_thread<0>;
static void run(_Ctype *c);
@ -238,7 +226,7 @@ namespace sthread
template <int thread_impl>
struct mutex_traits
{
using _Tmutex = typename IF<thread_impl == posix, pthread_mutex_t, Empty>::RET;
using _Tmutex = std::conditional_t<thread_impl == posix, pthread_mutex_t, Empty>;
using mutex_int_map = map<mmkey, pair<_Tmutex, int>, ltmmkey>;
static void init(_Tmutex &m);
static void lock(_Tmutex &m);
@ -406,7 +394,7 @@ namespace sthread
template <int thread_impl>
struct cond_traits
{
using _Tcond = typename IF<thread_impl == posix, pthread_cond_t, Empty>::RET;
using _Tcond = std::conditional_t<thread_impl == posix, pthread_cond_t, Empty>;
using _Tmutex = typename mutex_traits<thread_impl>::_Tmutex;
static void init(_Tcond &cond);
static void broadcast(_Tcond &cond);