How to port C++ std::is_reference<T> to D ?
wjoe
invalid at example.com
Wed May 6 09:40:47 UTC 2020
On Wednesday, 6 May 2020 at 09:19:10 UTC, drug wrote:
> 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?
yes, I did read the spec. I read the language spec on traits as
well as std.traits docs as well as searching the internet for a
solution since day before yesterday. But I couldn't bring it
together because
} else static if (__traits(isRef, T)) {
compiles, but e.g.
assert (modifier!(ref int) == "[out] ");
doesn't.
Anyways, thanks for your reply.
More information about the Digitalmars-d-learn
mailing list