strong_typedef | class template that creates a new type | Development Tools library
kandi X-RAY | strong_typedef Summary
kandi X-RAY | strong_typedef Summary
This is an implementation of a class template that provides a wrapper type that is convertible to and from the underlying type, but is distinct from it.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of strong_typedef
strong_typedef Key Features
strong_typedef Examples and Code Snippets
Community Discussions
Trending Discussions on strong_typedef
QUESTION
From what I can see BOOST_STRONG_TYPEDEF does not support move semantics(no move ctor/assignment).
Is this just an oversight(nobody updated old macro) or is there a more fundamental reason why strong typedefs are limited in this way?
...ANSWER
Answered 2020-May-05 at 20:47The fundamental reason would be that many boost libraries are still targetting pre-c++11 standard compilers¹, i.e. compilers that do not support move semantics.
I suppose for some compilers the tricks in Boost Move might be used, but I'm not sure that would be easy to apply transparently to strong typedefs.
However, I'd always roll my own strong typedef to do the job, as I've suggested fro other reasons, e.g. How do I strongly typedef non-primitive types?
¹ Boost Serialization is definitely one of these libraries
QUESTION
I have used BOOST_STRONG_TYPEDEF
before, mainly with std::string
and I got satisfactory results:
ANSWER
Answered 2017-Nov-27 at 14:32Reading http://www.boost.org/doc/libs/1_63_0/libs/serialization/doc/strong_typedef.html
The macro creates new classes for you already. The problem that you're having is that the conversion is working exactly as designed (as per the examples on their site; which also use primitive types).
I think the question about why they're different behaviors is different is the more interesting one; but ultimately the answer seems to be this isn't the library for you if you require this check to fail to compile.
QUESTION
I was supposing that numeric_limits::max() on a BOOST_STRONG_TYPEDEF defined type would give the same result than on the underlying type. But the following program shows that it is not the case (compiled with g++ or clang++ with boost 1.65):
...ANSWER
Answered 2019-Nov-12 at 13:35Your expectations are wrong. In a sense the effect you see is exactly what a strong typedef is made for. Your s
is not int
but a seperate type. std::numeric_limits
cannot possibly know about your type, hence as with any other custom type you would have to provide your own specialization to get the expected output.
QUESTION
I am using BOOST_STRONG_TYPEDEF
to prevent misuses of different string-based ID types. I am however running into compatibility problems between the original type and its typedef.
I have an std::string
which contains a list of IDs, separated by commas. I need to store them into a set. The code would look like:
ANSWER
Answered 2017-Mar-31 at 08:33The whole point of strong typedefs is to require an explicit conversion when creating the strong typedef out of its underlying type. So use an explicit conversion syntax:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install strong_typedef
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page