| |
| ▲ | 0x457 2 hours ago | parent | next [-] | | Well, in Rust, you can't make your own Box without using #[lang = "owned_box"] and #[fundamental], plus it has special orphan rule handling. The question is, at least for me, do you really miss out on anything by not having an ability to do so? I think you miss anything, but you gain a lot. | | |
| ▲ | aw1621107 2 hours ago | parent [-] | | > Well, in Rust, you can't make your own Box without using #[lang = "owned_box"] and #[fundamental], plus it has special orphan rule handling. Sure, but are those "just" characteristics of Rust's current implementation or are those inherent to a constructor-less model in general? The latter is the more interesting question to me in this particular context, and I think it's similar to the question you express. | | |
| ▲ | 0x457 an hour ago | parent [-] | | Fair. I think guaranteed in-place initialization is probably the strongest example of something that cannot be expressed through From or Default alone. There are proposals to solve this via traits. I haven't dug deep enough into them, but I'd assume those would be "special" traits that rely on compiler-provided semantics not otherwise expressible in ordinary library code. Right now, both Box::new() and the vec![] macro resort to compiler intrinsics (write_via_move and write_box_via_move), particularly to avoid unnecessary intermediate storage and excessive stack usage. |
|
| |
| ▲ | pjmlp 5 hours ago | parent | prev [-] | | Nope, because you also want C types, that now are C++ types by virtue of using a C++ compiler, to also share similar behaviours. Which is why the only difference between a struct and a class, is the default access method. Thus that C file could be made extensible in C++, with zero code changes on the call sites. | | |
| ▲ | pwdisswordfishq 5 hours ago | parent | next [-] | | What does this have to do with anything? | |
| ▲ | ninkendo 4 hours ago | parent | prev [-] | | They could have just as easily said "C semantics are used when we know we're parsing C code" and declared that C++ code doesn't have implicit constructors. No, the decision to have constructors was made because it's what they wanted to do when the language was designed. You can't lean on "but C" as an excuse when those problems are so easily solved other ways. |
|
|