Comments (6)
That's a good point, rkawulak! Would you be interested in submitting an appropriate change as a PR?
from gsl.
I could, but I'm not sure which approach is better. Allowing only for types with no alignment requirement would be much more restricting, but OTOH would be verifiable statically rather than only at runtime.
from gsl.
I think a bool template parameter on array_view that defaults to true can be used. If the argument for this parameter is true, then a runtime check is done.
from gsl.
I thought about this a bit further. If someone is using array_view to move to/from a byte representation, then it is their responsibility to ensure that the alignment requirements for their environment will be met. So I'm going to leave this implementation as-is.
Moving to/from byte representations is useful, but risky behavior at the best of times and - as it would be if the user was using reinterpret_cast themselves - it is up to the user to ensure it is safe to do so.
from gsl.
Makes sense for array_view. However, when the source array view element type isn't byte, it might be helpful to have a static_assert on the alignment. Would that be too noisy?
from gsl.
@neilmacintosh Then what's the point of those as_array_view functions if not to help catching misuse like that? Otherwise they would be of little use since the user can invoke reinterpret_cast by himself and make the dangerous operation more explicit.
BTW, as I understand it is not about MOVING to/from byte representation, but about INTERPRETING byte representation as objects IN PLACE. If you want to use raw bytes as an object, you either need to make sure the bytes are properly aligned (this is what a runtime alignment assert could verify) or, if you cannot control how the bytes are aligned (e.g. you got a buffer with raw frames from a networking layer) and you want to avoid copying the bytes in order to realign them properly, the only option is to only allow for reinterpretation as a type with no alignment requirement, which is rather quite constraining.
BTW2, I think is_trivial check would be more suitable than is_standard_layout when dealing with interpretation of raw bytes as objects in a standard-conforming way.
from gsl.
Related Issues (20)
- Doxygen documentation HOT 5
- Wrong Expects in gsl::at? HOT 5
- About release 4.0.0 HOT 2
- [cmake] GSL.natvis issues HOT 3
- ❓ Please take the GSL GitHub survey HOT 1
- Question: How to print a gsl::byte? HOT 2
- How to use the smartpointer overloads inside `<span_ext>`? HOT 1
- Purpose of `<span_ext>`
- gsl::not_null at compile time HOT 13
- Provide a "safe" and "simple" way for binary I/O HOT 2
- Type mismatch in span::operator[] HOT 4
- gsl.pc and gsl/gsl_rng.h files not found HOT 2
- CMake Error at CMakeLists.txt:14 (find_package): Could not find a package configuration file provided by "Microsoft.GSL" HOT 2
- Missing `swap` for `gsl::not_null` for move-only types HOT 4
- `GSL_SUPPRESS(y)` expands to `[[gsl::suppress("x")]]` for clang HOT 5
- Can not build with gcc13 because suggestion warning HOT 3
- gsl::not_null and std::variant are not fully compatible
- Reproducible build? HOT 2
- [Help] About the signed copy of my CLA HOT 1
- C++20 Modules Support? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gsl.