diff --git a/dynare++/kord/korder.hh b/dynare++/kord/korder.hh index efbba9041fe9881adfb825221f3433e7b5e7bfc6..ab9201554c92780af3597d2557155efca8cacf06 100644 --- a/dynare++/kord/korder.hh +++ b/dynare++/kord/korder.hh @@ -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 diff --git a/dynare++/tl/cc/sthread.hh b/dynare++/tl/cc/sthread.hh index aab785d300fb8d42660e7645b51cda43924efd11..50bc7c53d7a0c3044f6eb0ffc4e624bdc344aa36 100644 --- a/dynare++/tl/cc/sthread.hh +++ b/dynare++/tl/cc/sthread.hh @@ -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);