Comments (6)
Yes I know :(
This was a solution we came up with to avoid type_traits depending on MPL. And indeed it works well, but as you correctly point out the function cannot be constexpr
which is a serious issue.
I'm open to ideas as at present I don't know how to fix this!
from type_traits.
IIUC, the goal is to allow mpl::integral_c
/ mpl::bool_
to be incomplete when definining integral_constant
? Is the "lvalueness" of the conversion operators also significant? If not, something like (https://godbolt.org/z/JHKfSm):
template<class T, T> struct integral_c;
template<class T, T val>
struct integral_constant {
constexpr operator integral_c<T, val>() const noexcept {
return {};
}
};
constexpr integral_constant<int, 42> i42;
template<class T, T> struct integral_c {};
int main() {
integral_c<int, 42>(i42);
}
works, since return types need be complete when instantiating the body, but not the declaration, of a function. I assume that requiring completeness when instantiating the body isn't a huge bar, since presumably the caller wants to actually do something with the returned object. But this seems simple enough that it would have occurred to someone. Is there a requirement I'm missing?
from type_traits.
Nearly: we have tests which rely on dispatching without explicitly including MPL, for example this one https://github.com/boostorg/type_traits/blob/develop/test/mpl_interop_test1.cpp fails with your change.
I experimented with:
constexpr operator const mpl::integral_c<T, val>& ()const
{
return *static_cast<const mpl::integral_c<T, val>*>(nullptr);
}
Which passes all the type_traits tests, but breaks Boost.Test which manages to dereference the returned value, but only with MSVC :(
from type_traits.
If this conversion must be callable when mpl::integral_c
is incomplete then your proposal - whose return value cannot undergo lvalue-to-rvalue conversion - may be the best we can do. "This type needs to have a dependency on this other type but without having an actual dependency" is a peculiar requirement, but I'll accept on faith that there are good reasons for it that I don't want to invest the time to properly understand.
but breaks Boost.Test which manages to dereference the returned value, but only with MSVC :(
This is likely a case of MSVC's constexpr
evaluator performing lvalue-to-rvalue conversion when it should not: we have a few bugs to that effect IIRC. I'll dig into this and see if we can get the compiler fixed to unblock this change so we don't have to continue patching it.
(Related: I haven't had the opportunity to thank you in person for Boost::Math, which we use to implement the C++17 mathematical special functions in MSVC. Here's a virtual Thank You, which will have to do for now.)
from type_traits.
"This type needs to have a dependency on this other type but without having an actual dependency" is a peculiar requirement,
Indeed: it's legacy really, there was never supposed to be any dependency, but to work around broken compilers (which we no longer support), MPL needed to inject a bunch of code into type_traits. Over time a lot of code came to depend on the traits inheriting from mpl::true_ or mpl::false_ - mostly due to convenience. So... when we removed the no longer needed workarounds, the conversion operators were added to avoid breaking too much other stuff.
So... probably the right way to fix this is to stop relying on the conversion in Boost.Math. It's a rather tedious bit of editing, so it may have to wait for a day when I'm really properly bored ;)
from type_traits.
I was looking into the issue a while ago when I was trying to make boost::integral_constant
/boost::mpl::integral_c
/boost::mpl::bool_
convertible to std::integral_constant
for make transition to standard type traits easier, but I end up with nothing, except the bug in MSVC that prevents the main idea https://developercommunity.visualstudio.com/content/problem/417059/fails-to-compile-valid-template-template-parameter.html, and also discovered that this:
BOOST_CONSTEXPR operator mpl::integral_c<T, val>() const
{ return mpl::integral_c<T, val>(); }
...
BOOST_CONSTEXPR operator mpl::bool_<val>() const
{ return mpl::bool_<val>(); }
works fine on all three major compilers. I do not know if this is actually allowed, DR2335 seems to be about this uncertainty.
from type_traits.
Related Issues (20)
- Operator traits documentation does not mention C++11 implementation
- `-Wconversion` warning in `type_traits/is_complete.hpp` HOT 1
- `-Wundef` warnings in `is_mem_fun_pointer_impl.hpp` HOT 1
- Boost\libs\type_traits failed to build due to error C2338 on MSVC HOT 2
- -Wconversion warning with is_signed for enums HOT 1
- __has_trivial_assign etc. deprecated under clang 15 HOT 1
- boost::is_integral<char8_t>::value is false HOT 1
- type_traits: Deprecation warnings with clang 15 HOT 1
- more classification/traits
- is_floating_point does not contain any C++23 types HOT 1
- add/rename remove_cv_ref to (C++20 compatible) remove_cvref HOT 1
- add is_integer HOT 3
- add is_character HOT 1
- add is_number HOT 3
- add remove_cvptr HOT 1
- add is_bool HOT 3
- add is_quotrem_order HOT 2
- add is_logic HOT 2
- add is_function_pointer
- add dependent_false HOT 2
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 type_traits.