random

Benjamin Kosnik bkoz@redhat.com
Thu Apr 2 22:24:00 GMT 2009


> Here is my latest patch for random.
> 
> It is very much like the last patch that was put up except:
> 
> 1. Corrected template arg checks for mersenne_twister
> 2. An initializer_list ctor for seed_seq and a testsuite case
> 3. C++ style static casts in a few places

OK. Attached is a patch that fixes some issues, detailed below, and
gives me clean testresults on x86_64/linux. The issues are not serious
and I anticipate the cleanups will happen quickly after this goes in.

It is my plan to check this in today after waiting six more hours,
barring objections. It seems as if we are all on the same page WRT
getting this in first, and then working on trunk with less massive
patches to move incrementally forward. 

Details:

Ok. Some bits needed to be fixed up:

      struct _ShiftMin1
     { static const _UIntType __value =
      std::numeric_limits<_UIntType>::max(); };

won't compile. The C++0x syntax you are reaching for:

    { static constexpr _UIntType __value =
    std::numeric_limits<_UIntType>::max(); };
   
but it's not implemented at the moment.

So, I substituted:

{ static const _UIntType __value =
__gnu_cxx::__numeric_traits<_UIntType>::max; };

Which is our typical way of working around this until C++0x constexpr
support is in. It will be a happy day when __gnu_cxx::__numeric_traits
can get killed in favour of std::numeric_limits and constexpr.

Then there were some other qualification/uglification issues, and then
fixing up the testsuite to use mersenne_twister_engine.

After doing this, I ran into static_asserts in mersenne_twister_engine,
from:

+      static_assert(__m >= 1U && __n >= __m
+         && __w >= __r && __w >= __u
+         && __w >= __s && __w >= __t
+         && __w >= __l
+         && __w <=
  static_cast<size_t>(numeric_limits<_UIntType>::digits)
+         && __a <= _ShiftMin1<_UIntType, __w>::value
+         && __b <= _ShiftMin1<_UIntType, __w>::value
+         && __c <= _ShiftMin1<_UIntType, __w>::value,
+            "template arguments out of bounds"
+            " in mersenne_twister_engine");

So. While debugging this I came to the conclusion that a static_assert
statement that is composed of massive compound sub-statements as above
is pretty useless for quickly debugging what is wrong with a
14-parameter template. So, suggest using:

     static_assert(__m >= 1U,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__n >= __m,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__w >= __r,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__w >= __u,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__w >= __s,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__w >= __t,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__w >= __l,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__w <=
     static_cast<size_t>(numeric_limits<_UIntType>::digits),
            "mersenne_twister_engine template arguments out of bounds");

#if 0
      // XXX
      static_assert(__a <= __detail::_ShiftMin1<_UIntType,
__w>::__value,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__b <= __detail::_ShiftMin1<_UIntType,
__w>::__value,
            "mersenne_twister_engine template arguments out of bounds");
      static_assert(__c <= __detail::_ShiftMin1<_UIntType,
__w>::__value,
            "mersenne_twister_engine template arguments out of bounds");
#endif

Instead. Ie one statement per static_assert. This lead me to realize it
was the last 3 that were problematic. Of course, breaking apart the
compound static_assert means that the static_assert error message is
repeated and repeated and repeated, a nifty compile time solution
unknown.

;)

Still not quite sure the best way to handle this. Thoughts?

For the time being, due to this part of the patch seeming kind of at
issue already, I commented this the three problematic asserts and am
hoping your next pass will clean it up.

With these changes layered on top of your last patch, I see one failure:

FAIL: 26_numerics/random/mersenne_twister_engine/cons/default.cc
execution test

default.exe: /mnt/share/src/gcc/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc:42:
void test01(): Assertion `x.max() == 4294967295ul' failed.
FAIL: 26_numerics/random/mersenne_twister_engine/cons/default.cc
execution test

Instead, x.max() == 2147483648

I've temporarily disabled this line. 


tested x86_64/linux

best,
benjamin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20090402-2.patch.bz2
Type: application/x-bzip
Size: 46251 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20090402/cfd42167/attachment.bin>


More information about the Libstdc++ mailing list