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

drug drug2004 at bk.ru
Wed May 6 09:19:10 UTC 2020


06.05.2020 12:07, wjoe пишет:
> 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.
> 
> 
> 

did you try https://dlang.org/spec/traits.html#isRef?


More information about the Digitalmars-d-learn mailing list