On Friday, 17 December 2021 at 13:00:55 UTC, Ali Çehreli wrote:
On 12/17/21 1:57 AM, bauss wrote:
> You can also do it as a normal template:
>
> ```d
> template is_same(alias value, T)
> {
> enum is_same = is(typeof(value) == T);
> }
> ```
And even shorter by realizing that it's an eponymo
On Friday, 17 December 2021 at 16:02:45 UTC, RazvanN wrote:
There is also a compiler trait [1] which can do that for you:
```d
void main()
{
int val = 10;
static if (__traits(isSame, typeof(val), int)) {}
}
```
[1] https://dlang.org/spec/traits.html#isSame
Thanks! The other options
On Friday, 17 December 2021 at 18:51:56 UTC, Ali Çehreli wrote:
On 12/17/21 10:01 AM, Tejas wrote:
> [...]
Storage,
There is no such requirement nor guarantee.
[...]
Well, I got completely mislead by my experiment 😓
```d
struct S
{
~this() immutable {}
}
void main()
{
immutable S s
On 12/17/21 10:01 AM, Tejas wrote:
> I think since `immutable` objects are kept in Read Only Storage,
There is no such requirement nor guarantee.
> you
> can't call destructors on them
Destructor is nothing but a piece of code that is executed when an
object's life ends. A destructor need not
On Friday, 17 December 2021 at 18:32:43 UTC, Denis Feklushkin
wrote:
On Friday, 17 December 2021 at 18:02:52 UTC, Tejas wrote:
I improved your sample:
```d
immutable struct S
{
~this() {}
}
immutable struct S2
{
S sss;
~this() {}
}
void main()
{
S2 s = S2();
}
```
```
Error:
On Friday, 17 December 2021 at 18:02:52 UTC, Tejas wrote:
I improved your sample:
```d
immutable struct S
{
~this() {}
}
immutable struct S2
{
S sss;
~this() {}
}
void main()
{
S2 s = S2();
}
```
```
Error: `immutable` method `serializer_bug.S.~this` is not
callable using a m
On Friday, 17 December 2021 at 18:19:34 UTC, Denis Feklushkin
wrote:
On Friday, 17 December 2021 at 18:01:03 UTC, Tejas wrote:
I think since `immutable` objects are kept in Read Only Storage
Some of them can be stored in ROM in some cases, but actually
"immutable" keyword means "not mutable
On Friday, 17 December 2021 at 18:01:03 UTC, Tejas wrote:
I think since `immutable` objects are kept in Read Only Storage
Some of them can be stored in ROM in some cases, but actually
"immutable" keyword means "not mutable for whole its lifetime"
On Friday, 17 December 2021 at 18:01:03 UTC, Tejas wrote:
On Friday, 17 December 2021 at 17:34:05 UTC, Denis Feklushkin
wrote:
On Friday, 17 December 2021 at 17:27:53 UTC, Denis Feklushkin
wrote:
[...]
("serializer_bug" is just name of my local .d file)
I think since `immutable` objec
On Friday, 17 December 2021 at 17:34:05 UTC, Denis Feklushkin
wrote:
On Friday, 17 December 2021 at 17:27:53 UTC, Denis Feklushkin
wrote:
~this() {} // Comment out this to fix this compilation
error:
// Error: `immutable` method `serializer_bug.Imm.~this` is
("serializer_bug" is ju
On Friday, 17 December 2021 at 17:27:53 UTC, Denis Feklushkin
wrote:
~this() {} // Comment out this to fix this compilation
error:
// Error: `immutable` method `serializer_bug.Imm.~this` is
("serializer_bug" is just name of my local .d file)
```d
/+ dub.json:
{
"name": "test",
"dependencies": {
}
}
+/
struct S
{
~this() {}
}
immutable class Imm
{
S s; // this is immutable value because whole class is
immutable
this()
{
s = S();
}
~this() {} // Comment out this to fix this compilation error:
On Friday, 17 December 2021 at 07:52:18 UTC, rempas wrote:
I want to use an expression and put it in place inside the `if`
parentheses. The expression is: `is(typeof(val) == type)`. I
want to use a template called "is_same" that will take the
value and a type to place them to the respective pla
On 12/17/21 1:57 AM, bauss wrote:
> You can also do it as a normal template:
>
> ```d
> template is_same(alias value, T)
> {
> enum is_same = is(typeof(value) == T);
> }
> ```
And even shorter by realizing that it's an eponymous template:
enum is_same(alias value, T) = is(typeof(value) ==
On Friday, 17 December 2021 at 08:59:19 UTC, rempas wrote:
On Friday, 17 December 2021 at 08:44:39 UTC, Mitacha wrote:
It isn't really about limitation of templates. You're trying
to use mixin template and it's main purpose is to inject
declarations. If you want to replace `is expression` wit
On Friday, 17 December 2021 at 08:44:39 UTC, Mitacha wrote:
It isn't really about limitation of templates. You're trying to
use mixin template and it's main purpose is to inject
declarations. If you want to replace `is expression` with
template you could use something like this:
```d
bool i
On Friday, 17 December 2021 at 07:52:18 UTC, rempas wrote:
I want to use an expression and put it in place inside the `if`
parentheses. The expression is: `is(typeof(val) == type)`. I
want to use a template called "is_same" that will take the
value and a type to place them to the respective pla
17 matches
Mail list logo