Comments (10)
I'm assuming those are macros?
I'll have to think about that. I can sort of replicate the problem with the windows API which defines a _T
macro, which originally conflicted with the Tesla definition. There was a reddit comment which had a suggestion for de-conflicting user-defined literals and macros which I can try out.
If that doesn't work I'm personally not opposed to the #undef
s. It can be documented, and I tend to think the people who macro-ize their code are not the same people looking for type-safe c++14 libraries.
from units.
Also, would you mind copy/pasting the original ctype.h
definitions into the issue? I can try to define them manually and come up with some unit testing.
from units.
To be fair symbols starting with underscore and uppercase letter are reserved by the C++ standard. I expect more clashes on other platforms. We need to find a solution that scales. Personally I would remove the underscore, don't mind writing literals as 12.0V
or 13.32mA
myself :)
from units.
Yikes, that was a big oversight on my part. I should have googled it. I think we probably have to do that, but I'll have to rev the version to 3.x since it will break every single piece of code currently using the library.
And then I think if I'm going to change the interface so destructively, I might also move the _t
suffix from the unit container types to the unit tag types (and probably change it to _tag
as well). It's both annoying, and apparently reserved by POSIX
.
from units.
I agree, perhaps a quick documentation update is enough for v2.2.x, directing users to #undef
any clashing symbols.
from units.
Yup, I think I'll put out 2.2 as the last release with that interface, and I should be able to roll out a 3.0 relatively quickly.
@martinmoene as a fellow unit conversion aficionado, I'm curious if you have any thoughts on this proposed interface change? It may also be an issue in PhysUnits-CT-Cpp11.
from units.
PhysUnits-CT-Cpp11 does have the same issue.
Note that UDLs are in namespace units::literals
and --apart from macros-- only might clash when using
(necessary to use them) and using
something else that contains the same name(s).
I'd much like to see this units library evolve into a proposal for C++ standardization. As such it might be written as std::experimental::units
, nullifying the issue ;)
from units.
So it looks like the developer is already on top of this, but there's a C++14 feature that solves this issue. If there's no space after the quotes in the definition (ex.) operator ""_T
, then the macro _T
is not expanded. This allows the use of reserved words as literal suffixes.
See here for details: http://en.cppreference.com/w/cpp/language/user_literal (search for "defined-string")
from units.
@EvanBalster so a few people have made that comment to me, but that's how the library is currently implemented and I've had existential problems when including <Windows.h>
with VS2015 and having the macro still clash. Maybe it's just a bug on their end, and maybe gcc-arm isn't fully c++14 compliant?
@pvaibhav so I think in the end I'm actually not going to change the UDLs because there's a requirement that suffixes must begin with an underscore, which kind of ruins our whole idea. Additionally, per @EvanBalster 's comment, UDLs are intended to be able to override underscore + capital letter (at least with a fully conformant c++14 compiler).
I still plan make the documentation update (eventually), and I'll probably change _Te
to _T
and just warn the user to undef
it.
from units.
This is now going to go into v2.2.0 as a documentation change, which warns about some known #undef
statements that will have to be made when compiling with c++11.
from units.
Related Issues (20)
- Conan package out of date HOT 2
- Undefined references to .name() and .abbreviation() HOT 1
- Incorrect enable_if condition for operator+ HOT 1
- Request for branch and pull request permissions HOT 5
- percent_t FROM double and TO double are different HOT 9
- 2.3.3 does not compile
- Add a way to specify units when "downcasting" to numeric type HOT 2
- Support the MSFS SDK HOT 2
- Empty base class optimization for MSVC
- Does not compile with GCC 12 HOT 1
- raw() and value() is error prone HOT 4
- [Bug] i386 (32-bit) fails to compile
- Shouldn't the naming of units::torque::foot_pound be changed
- v2 -> v3 porting HOT 2
- Need help implementing resistance as a new custom unit. HOT 2
- unit conversion emits a surprisingly high amount of instructions
- Compilation under MINGW
- Math functions not compatible with percent HOT 1
- Status of the project HOT 14
- Units are not installed as a system library HOT 1
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 units.