Use C++14 std::conditional_t (instead of custom IF template)
parent
922014c2fa
commit
38c24347ff
|
@ -41,6 +41,7 @@
|
||||||
#include <dynlapack.h>
|
#include <dynlapack.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#define TYPENAME typename
|
#define TYPENAME typename
|
||||||
|
|
||||||
|
@ -69,35 +70,23 @@ class UnfoldedZXContainer;
|
||||||
class FoldedGXContainer;
|
class FoldedGXContainer;
|
||||||
class UnfoldedGXContainer;
|
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>
|
template <int type>
|
||||||
class ctraits
|
class ctraits
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { fold, unfold };
|
enum { fold, unfold };
|
||||||
using Ttensor = TYPENAME IF<type == fold, FGSTensor, UGSTensor>::RET;
|
using Ttensor = std::conditional_t<type == fold, FGSTensor, UGSTensor>;
|
||||||
using Ttensym = TYPENAME IF<type == fold, FFSTensor, UFSTensor>::RET;
|
using Ttensym = std::conditional_t<type == fold, FFSTensor, UFSTensor>;
|
||||||
using Tg = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
|
using Tg = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
|
||||||
using Tgs = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
|
using Tgs = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
|
||||||
using Tgss = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
|
using Tgss = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
|
||||||
using TG = TYPENAME IF<type == fold, FGSContainer, UGSContainer>::RET;
|
using TG = std::conditional_t<type == fold, FGSContainer, UGSContainer>;
|
||||||
using TZstack = TYPENAME IF<type == fold, FoldedZContainer, UnfoldedZContainer>::RET;
|
using TZstack = std::conditional_t<type == fold, FoldedZContainer, UnfoldedZContainer>;
|
||||||
using TGstack = TYPENAME IF<type == fold, FoldedGContainer, UnfoldedGContainer>::RET;
|
using TGstack = std::conditional_t<type == fold, FoldedGContainer, UnfoldedGContainer>;
|
||||||
using Tm = TYPENAME IF<type == fold, FNormalMoments, UNormalMoments>::RET;
|
using Tm = std::conditional_t<type == fold, FNormalMoments, UNormalMoments>;
|
||||||
using Tpol = TYPENAME IF<type == fold, FTensorPolynomial, UTensorPolynomial>::RET;
|
using Tpol = std::conditional_t<type == fold, FTensorPolynomial, UTensorPolynomial>;
|
||||||
using TZXstack = TYPENAME IF<type == fold, FoldedZXContainer, UnfoldedZXContainer>::RET;
|
using TZXstack = std::conditional_t<type == fold, FoldedZXContainer, UnfoldedZXContainer>;
|
||||||
using TGXstack = TYPENAME IF<type == fold, FoldedGXContainer, UnfoldedGXContainer>::RET;
|
using TGXstack = std::conditional_t<type == fold, FoldedGXContainer, UnfoldedGXContainer>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The |PartitionY| class defines the partitioning of state variables
|
/* The |PartitionY| class defines the partitioning of state variables
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace sthread
|
namespace sthread
|
||||||
{
|
{
|
||||||
|
@ -76,19 +77,6 @@ namespace sthread
|
||||||
class Empty
|
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};
|
enum { posix, empty};
|
||||||
|
|
||||||
|
@ -103,7 +91,7 @@ namespace sthread
|
||||||
template <int thread_impl>
|
template <int thread_impl>
|
||||||
struct thread_traits
|
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 _Ctype = thread<0>;
|
||||||
using _Dtype = detach_thread<0>;
|
using _Dtype = detach_thread<0>;
|
||||||
static void run(_Ctype *c);
|
static void run(_Ctype *c);
|
||||||
|
@ -238,7 +226,7 @@ namespace sthread
|
||||||
template <int thread_impl>
|
template <int thread_impl>
|
||||||
struct mutex_traits
|
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>;
|
using mutex_int_map = map<mmkey, pair<_Tmutex, int>, ltmmkey>;
|
||||||
static void init(_Tmutex &m);
|
static void init(_Tmutex &m);
|
||||||
static void lock(_Tmutex &m);
|
static void lock(_Tmutex &m);
|
||||||
|
@ -406,7 +394,7 @@ namespace sthread
|
||||||
template <int thread_impl>
|
template <int thread_impl>
|
||||||
struct cond_traits
|
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;
|
using _Tmutex = typename mutex_traits<thread_impl>::_Tmutex;
|
||||||
static void init(_Tcond &cond);
|
static void init(_Tcond &cond);
|
||||||
static void broadcast(_Tcond &cond);
|
static void broadcast(_Tcond &cond);
|
||||||
|
|
Loading…
Reference in New Issue