How to port C++ std::is_reference<T> to D ?

wjoe invalid at example.com
Wed May 6 09:07:22 UTC 2020


Hello,

I'm choking on a piece of C++ I have no idea about how to 
translate to D.

   template <typename T,
         typename std::enable_if< std::is_const<T>::value == true, 
void>::type* = nullptr>
     constexpr const char *modifier() const {
         return "[in] ";
     }

   template <typename T,
         typename std::enable_if< std::is_reference<T>::value == 
true, void>::type* = nullptr>
     constexpr const char *modifier() const {
         return "[out] ";
     }

my attempt at it is like this:

   template modifier(T) {

       static if (is (T==const)) {

           const char* modifier = "[in] ";

       } else static if (/* T is a reference ?*/) { // [*]

           const char* modifier = "[out] ";
       }
   }

but even if I could e.g. say something like
   is(T == ref R, R),
   auto a = modifier!(ref T);
wouldn't work.





More information about the Digitalmars-d-learn mailing list