Closed Lagrang3 closed 3 years ago
It's the way the std is defined: none of the code in is_signed
/ is_unsigned
are required to be false for user defined types.
You could conceivably submit a feature request to your compiler vendor to use std::numeric_limits<>::is_integer && !std::numeric_limits<>::is_signed
in place of is_unsigned<>::value
in order to support UDT's.
@jzmaddock I don't understand.
Assume is_unsigned
is false for every user defined type, then there is no way by construction that I can use std::independent_bits_engine
together with boost::multiprecision::uint512_t
. But that doesn't make any sense.
Without that static_assertion
the templates play just fine.
Abiding to this rule would be like accepting that std::map
can only work on builtin type keys, by construction.
Are you saying that std::independent_bits_engine<std::mt19937_64,512,boost::multiprecision::uint512_t>
makes no sense?
Does std::independent_bits_engine<std::mt19937_64,512,Uint>
work only when Uint
is a builtin type? I don't think so. Boost's version works out of the box boost::random::independent_bits_engine<std::mt19937_64,512,boost::multiprecision::uint512_t>
.
Are you saying that
std::independent_bits_engine<std::mt19937_64,512,boost::multiprecision::uint512_t>
makes no sense?
I'm not sure if I completely understand the depth of the question. But I think John is saying that for User-Defined-Types most (if not all) of the features of <type_traits>
are not defined and not foreseen to be defined by the standard.
This could be a blocking point that might be at the bottom of this issue?
@ckormanyos Thank you for the answer. I want to understand what's going on here.
To put it simple, the questions are:
will std::independent_bits_engine<std::mt19937_64,X,boost::multiprecision::uint512_t>
work as I would expect? That is generating random uint512_t
from 0
to (1<<X)- 1
, if I just ignore the static_assertion
.
if the answer is YES, then I don't see the point in placing such static_assertion
enforcing is_unsigned
knowing that custom types are not meant to satisfy the condition. Am I right, or is there a fundamental reason blocking the way?
can you point me out where is it written that
the
type_traits
is_signed
/is_unsigned
are required to be false for user defined types.
will std::independent_bits_engine<std::mt19937_64,X,boost::multiprecision::uint512_t> work as I would expect? That is generating random uint512_t from 0 to (1<<X)- 1, if I just ignore the static_assertion.
From C++20 26.6.2.1:
"Throughout this subclause 26.6, the effect of instantiating a template: ... that has a template type parameter named UIntType is undefined unless the corresponding template argument is cv-unqualified and is one of unsigned short, unsigned int, unsigned long, or unsigned long long."
So it's undefined behaviour.
can you point me out where is it written that the type_traits is_signed / is_unsigned are required to be false for user defined types.
C++20 table 49:
"is_signed: If is_arithmetic_v
And for is_arithmetic
, "T is an arithmetic type (6.8.1)", note that "arithmetic type" applies only to the built in floating point and integral types.
Boost's version works out of the box
Yes, because we invested significant effort to make it so.
@jzmaddock Thank you. I won't bother anymore.
Yes, because we invested significant effort to make it so.
Good job!
Well, I guess std::independent_bits_engine
and boost::independent_bits_engine
are implemented in different ways.
I wonder why I cannot build an
std::independent_bits_engine
templated on aboost::multiprecision::uint512_t
?Here's a minimal example
However, if I manually set the
is_unsigned
trait ofuint512_t
thenstd::independent_bits_engine
compiles.Is this behavior made on purpose or is it a type traits feature missing here?