Comments (3)
I think there are several ways:
- Introduce a strongly indexed container, by reusing vector:
** with public inheritance: https://godbolt.org/z/1s4vnP
** with private inheritance: https://godbolt.org/z/z49jax - Use a strongly indexed reference to a container: https://godbolt.org/z/nv7Tq9
Do you think either one of these solutions would allow to write the code you had in mind?
from namedtype.
Yes, both of them achieve exactly what I had in mind, however, implementation-wise, inheriting from an stl container is generally not a great practice.
from namedtype.
FWIW, some sort of half-automatic proxy wrapper might be great. I was hoping to combine this library with a units library, so that we have both semantic types, and correct phyiscal units/dimensions in our code. And all this would need to operate with matrix, vector, and quaternion types - quite a bit to juggle! So far, NamedType wrapping around boost::qvm is working quite nicely, albeit without the units support. This'll likely need some sort of proxy wrapper. We also have some Mats from OpenCV. This would be one example where being able to index into an opaque structure would be really powerful, if it could be done. QVM is so-designed that it's working nicely enough to have the NamedTypoe on the outside, as QVM is designed explicitly to operate on different (incompatible) types, and is thus mostly free-functions. But CV's Mat would not be so easy, and was one justifying reason for moving away from it and using this lib - access is always risky and very much relies on runtime support, including the type of data it's storing. It's all held behind one single type.
Tl;Dr - I imagine a composition proxy wrapper might work quite powerfully here - a more generic version of the reference version above, I guess - perhaps using some specialised traits to define how to access the wrapped object, with some sensible automatic defaults, like for operator[]. And if done well, I'd hope it would compile away to the same binary format, a bit like how std::chrono evaporates after build-time, and I believe NamedType itself does. Perhaps NamedContainer<Key, Value>, for a rough way of accessing - for things like list and vector, the key becomes more of an index. Am guessing map and set will work as-is, although may be wrong.
from namedtype.
Related Issues (20)
- Support default values for named arguments HOT 2
- Undesirable inclusion of `<iostream>` for freestanding compilers HOT 1
- Error "expression did not evaluate to a constant" with latest MSVC 19.8.5
- gcc 9.3 claims operator++ is ambiguous HOT 1
- tuple of NamedTypes HOT 1
- Missing skills mixin for equality only HOT 2
- The skills for ++ / -- don't compile HOT 1
- Overhead? HOT 1
- Add Ability to Disable Default-Constructor HOT 1
- Concepts for Skills should be Separated from the NamedType
- Adding skill to explicitly convert from ArduinoJson JsonVariantConst
- Dealing with non-copyable and non-movable types
- Failure to perform standard compile time checks
- Packaging note for Arch Linux HOT 1
- Default constructor value behavior change
- Concerning bitwise operations HOT 1
- How about a new release? HOT 3
- do the arguments require the correct order? HOT 1
- Trait `Formatable` for std::format in C++20
- <iostream> still included in embedded systems
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 namedtype.