digitalmars.D.learn - Bind C++ template specialized with void parameter
- Gregor =?UTF-8?B?TcO8Y2ts?= (31/31) Feb 28 2024 I have roughly the following code in C++ (vastly simplified from
- DUser (25/28) Feb 29 2024 Did you mean any of these?
- Gregor =?UTF-8?B?TcO8Y2ts?= (6/34) Feb 29 2024 Thanks! This got me unstuck. I've picked the first solution. It
I have roughly the following code in C++ (vastly simplified from
reality):
```cpp
template<typename T>
class Wrapper {
private:
T t;
bool valid;
public:
bool isValid() { return valid; }
};
template<>
class Wrapper\<void> {
private:
bool valid;
public:
bool isValid() { return valid; }
};
```
I can bind Wrapper\<T> from D with no problem:
```d
extern(C++, class)
class Wrapper(T) {
private T t;
private bool valid;
public final isValid();
}
```
But how can I bind Wrapper\<void> in D? Specifically, how do I
even express that template specialization in D syntax?
Gregor
Feb 28 2024
On Wednesday, 28 February 2024 at 22:48:33 UTC, Gregor Mückl wrote:... But how can I bind Wrapper\<void> in D? Specifically, how do I even express that template specialization in D syntax?Did you mean any of these? 1. Parameter specialization: ```d extern(C++, class): class Wrapper(T) {...} class Wrapper(T : void) {...} ``` 2. Template constraints: ```d extern(C++, class): class Wrapper(T) if(!is(T == void)) {...} class Wrapper(T) if(is(T == void)) {...} ``` 3. `static if`: ```d extern(C++, class) class Wrapper(T) { static if (!is(T == void)) private T t; private bool valid; public final isValid(); } ```
Feb 29 2024
On Thursday, 29 February 2024 at 10:30:59 UTC, DUser wrote:On Wednesday, 28 February 2024 at 22:48:33 UTC, Gregor Mückl wrote:Thanks! This got me unstuck. I've picked the first solution. It mirrors the C++ code nicely. The embarrassing part is that I should have known the other two options, but my head got completely stuck trying to convert C++ to D too literally.... But how can I bind Wrapper\<void> in D? Specifically, how do I even express that template specialization in D syntax?Did you mean any of these? 1. Parameter specialization: ```d extern(C++, class): class Wrapper(T) {...} class Wrapper(T : void) {...} ``` 2. Template constraints: ```d extern(C++, class): class Wrapper(T) if(!is(T == void)) {...} class Wrapper(T) if(is(T == void)) {...} ``` 3. `static if`: ```d extern(C++, class) class Wrapper(T) { static if (!is(T == void)) private T t; private bool valid; public final isValid(); } ```
Feb 29 2024








Gregor =?UTF-8?B?TcO8Y2ts?= <gregormueckl gmx.de>