This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: random numbers in bulk


On 26 August 2012 18:34, Jonathan Wakely wrote:
> On 26 August 2012 18:19, Ulrich Drepper wrote:
>> Also, I consider the interface clean and now very C++-y.  Iterators
>> are used and transparently all kinds of overloads are possible.  Only
>> the iterator variants need to be documented, making the extensions
>> easy to use.  The only minor complication is that the pointer type had
>> to be introduced (or something like __normal_iterator has to be
>> reinvented).
>
> It would be a lot easier to read with a typedef for the iterator type:
>
>       template<typename _UniformRandomNumberGenerator>
>         void
>         __generate(result_type* __f, result_type* __t,
>                    _UniformRandomNumberGenerator& __urng,
>                    const param_type& __p)
>         { this->__generate(__iterator(__f), __iterator(__t), __urng, __p); }
>
>     private:
>       typedef result_type* pointer;
>       typedef
>         __gnu_cxx::__normal_iterator<result_type*, uniform_int_distribution>
>         __iterator;
>
> There's no need to qualify std::uniform_int_distribution and include
> the template argument list, within the class scope the class' own name
> is injected and can be used safely.

Or define the typedef locally to the function:

      template<typename _UniformRandomNumberGenerator>
	void
	__generate(result_type* __f, result_type* __t,
		   _UniformRandomNumberGenerator& __urng,
		   const param_type& __p)
	{
	  typedef __gnu_cxx::__normal_iterator<result_type*,
					       uniform_int_distribution>
					       __iterator;
	  this->__generate(__iterator(__f), __iterator(__t), __urng, __p);
	}

But I've just seen Paolo's suggestion for a __generate_impl that both
use, and I prefer that idea.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]