random: use decltype auto for wrapper functions

This commit is contained in:
Danny Robson 2018-11-28 15:24:01 +11:00
parent 532bd3b706
commit c7eb82c993

View File

@ -91,17 +91,22 @@ namespace cruft::random {
/// This is primarily a convenience helper around the uniform_distribution
/// type.
template <typename ValueT, typename GeneratorT>
auto
decltype(auto)
uniform (ValueT lo, ValueT hi, GeneratorT &&gen)
{
return uniform_distribution<ValueT> { lo, hi } (gen);
return uniform_distribution<ValueT> { lo, hi } (
std::forward<GeneratorT> (gen)
);
}
///------------------------------------------------------------------------
/// Return a value uniformly random chosen value between lo and hi.
///
/// Interval bounds are treated as per the standard Generator
/// implementations; ie, inclusive for integers, exclusive upper for reals.
template <typename T>
auto
decltype(auto)
uniform (T lo, T hi)
{
return uniform<T> (lo, hi, generator ());
@ -115,7 +120,8 @@ namespace cruft::random {
typename GeneratorT,
typename = std::enable_if_t<std::is_floating_point_v<ValueT>>
>
auto uniform (GeneratorT &&gen)
decltype(auto)
uniform (GeneratorT &&gen)
{
return uniform<ValueT> (ValueT{0}, ValueT{1}, std::forward<GeneratorT> (gen));
}
@ -127,7 +133,8 @@ namespace cruft::random {
typename ValueT,
typename = std::enable_if_t<std::is_floating_point_v<ValueT>>
>
auto uniform (void)
decltype(auto)
uniform (void)
{
return uniform<ValueT> (ValueT{0}, ValueT{1}, generator ());
}