13
submitted 10 months ago* (last edited 10 months ago) by [email protected] to c/[email protected]

C++ trick I pulled today. Like an explicit constructor but context dependent. Any alternatives from folks who've needed to do similar? One thing I still need to dig into a little deeper is how copy elision behaves here.

you are viewing a single comment's thread
view the rest of the comments
[-] [email protected] 2 points 9 months ago

For the array type it can be useful to allow implicit copy to different arithmetic types (design choice, I'm now back to explicit constructors to disallow this for what it's worth). If allowed though, I still wanted a compile time check like this to ensure that it wasn't happening by accident in particular circumstances.

this post was submitted on 15 Nov 2023
13 points (100.0% liked)

C++

1718 readers
8 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS