common: Swap C++14 template type aliases for variables

C++14 provides the ability to define template variables, which the C++17
library puts to good use. We define those same aliases.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
This commit is contained in:
Adam C. Emerson 2017-12-09 01:42:35 -05:00
parent 70da1eed80
commit bbe0afff64
5 changed files with 172 additions and 76 deletions

View File

@ -21,18 +21,119 @@
// Library code from C++14 that can be implemented in C++11.
namespace ceph {
template<typename T>
using remove_extent_t = typename std::remove_extent<T>::type;
template<typename T>
using remove_reference_t = typename std::remove_reference<T>::type;
template<typename T>
using result_of_t = typename std::result_of<T>::type;
// Template variable aliases from C++17 <type_traits>
// primary type categories
template<class T> constexpr bool is_void_v = std::is_void<T>::value;
template<class T> constexpr bool is_null_pointer_v =
std::is_null_pointer<T>::value;
template<class T> constexpr bool is_integral_v = std::is_integral<T>::value;
template<class T> constexpr bool is_floating_point_v =
std::is_floating_point<T>::value;
template<class T> constexpr bool is_array_v = std::is_array<T>::value;
template<class T> constexpr bool is_pointer_v = std::is_pointer<T>::value;
template<class T> constexpr bool is_lvalue_reference_v =
std::is_lvalue_reference<T>::value;
template<class T> constexpr bool is_rvalue_reference_v =
std::is_rvalue_reference<T>::value;
template<class T> constexpr bool is_member_object_pointer_v =
std::is_member_object_pointer<T>::value;
template<class T> constexpr bool is_member_function_pointer_v =
std::is_member_function_pointer<T>::value;
template<class T> constexpr bool is_enum_v = std::is_enum<T>::value;
template<class T> constexpr bool is_union_v = std::is_union<T>::value;
template<class T> constexpr bool is_class_v = std::is_class<T>::value;
template<class T> constexpr bool is_function_v = std::is_function<T>::value;
template<typename T>
using decay_t = typename std::decay<T>::type;
// composite type categories
template<class T> constexpr bool is_reference_v = std::is_reference<T>::value;
template<class T> constexpr bool is_arithmetic_v = std::is_arithmetic<T>::value;
template<class T> constexpr bool is_fundamental_v =
std::is_fundamental<T>::value;
template<class T> constexpr bool is_object_v = std::is_object<T>::value;
template<class T> constexpr bool is_scalar_v = std::is_scalar<T>::value;
template<class T> constexpr bool is_compound_v = std::is_compound<T>::value;
template<class T> constexpr bool is_member_pointer_v =
std::is_member_pointer<T>::value;
template<bool T, typename F = void>
using enable_if_t = typename std::enable_if<T,F>::type;
// type properties
template<class T> constexpr bool is_const_v = std::is_const<T>::value;
template<class T> constexpr bool is_volatile_v = std::is_volatile<T>::value;
template<class T> constexpr bool is_trivial_v = std::is_trivial<T>::value;
template<class T> constexpr bool is_trivially_copyable_v =
std::is_trivially_copyable<T>::value;
template<class T> constexpr bool is_standard_layout_v =
std::is_standard_layout<T>::value;
template<class T> constexpr bool is_pod_v = std::is_pod<T>::value;
template<class T> constexpr bool is_empty_v = std::is_empty<T>::value;
template<class T> constexpr bool is_polymorphic_v =
std::is_polymorphic<T>::value;
template<class T> constexpr bool is_abstract_v = std::is_abstract<T>::value;
template<class T> constexpr bool is_final_v = std::is_final<T>::value;
template<class T> constexpr bool is_signed_v = std::is_signed<T>::value;
template<class T> constexpr bool is_unsigned_v = std::is_unsigned<T>::value;
template<class T, class... Args> constexpr bool is_constructible_v =
std::is_constructible<T, Args...>::value;
template<class T> constexpr bool is_default_constructible_v =
std::is_default_constructible<T>::value;
template<class T> constexpr bool is_copy_constructible_v =
std::is_copy_constructible<T>::value;
template<class T> constexpr bool is_move_constructible_v =
std::is_move_constructible<T>::value;
template<class T, class U> constexpr bool is_assignable_v =
std::is_assignable<T, U>::value;
template<class T> constexpr bool is_copy_assignable_v =
std::is_copy_assignable<T>::value;
template<class T> constexpr bool is_move_assignable_v =
std::is_move_assignable<T>::value;
template<class T> constexpr bool is_destructible_v =
std::is_destructible<T>::value;
template<class T, class... Args> constexpr bool is_trivially_constructible_v =
std::is_trivially_constructible<T, Args...>::value;
template<class T> constexpr bool is_trivially_default_constructible_v =
std::is_trivially_default_constructible<T>::value;
template<class T> constexpr bool is_trivially_copy_constructible_v =
std::is_trivially_copy_constructible<T>::value;
template<class T> constexpr bool is_trivially_move_constructible_v =
std::is_trivially_move_constructible<T>::value;
template<class T, class U> constexpr bool is_trivially_assignable_v =
std::is_trivially_assignable<T, U>::value;
template<class T> constexpr bool is_trivially_copy_assignable_v =
std::is_trivially_copy_assignable<T>::value;
template<class T> constexpr bool is_trivially_move_assignable_v =
std::is_trivially_move_assignable<T>::value;
template<class T> constexpr bool is_trivially_destructible_v =
std::is_trivially_destructible<T>::value;
template<class T, class... Args> constexpr bool is_nothrow_constructible_v =
std::is_nothrow_constructible<T, Args...>::value;
template<class T> constexpr bool is_nothrow_default_constructible_v =
std::is_nothrow_default_constructible<T>::value;
template<class T> constexpr bool is_nothrow_copy_constructible_v =
std::is_nothrow_copy_constructible<T>::value;
template<class T> constexpr bool is_nothrow_move_constructible_v =
std::is_nothrow_move_constructible<T>::value;
template<class T, class U> constexpr bool is_nothrow_assignable_v =
std::is_nothrow_assignable<T, U>::value;
template<class T> constexpr bool is_nothrow_copy_assignable_v =
std::is_nothrow_copy_assignable<T>::value;
template<class T> constexpr bool is_nothrow_move_assignable_v =
std::is_nothrow_move_assignable<T>::value;
template<class T> constexpr bool is_nothrow_destructible_v =
std::is_nothrow_destructible<T>::value;
template<class T> constexpr bool has_virtual_destructor_v =
std::has_virtual_destructor<T>::value;
// type property queries
template<class T> constexpr size_t alignment_of_v = std::alignment_of<T>::value;
template<class T> constexpr size_t rank_v = std::rank<T>::value;
template<class T, unsigned I = 0> constexpr size_t extent_v =
std::extent<T, I>::value;
// type relations
template<class T, class U> constexpr bool is_same_v = std::is_same<T, U>::value;
template<class Base, class Derived> constexpr bool is_base_of_v =
std::is_base_of<Base, Derived>::value;
template<class From, class To> constexpr bool is_convertible_v =
std::is_convertible<From, To>::value;
namespace _backport14 {
template<typename T>
@ -57,7 +158,7 @@ inline typename uniquity<T>::datum make_unique(Args&&... args) {
template<typename T>
inline typename uniquity<T>::array make_unique(std::size_t n) {
return std::unique_ptr<T>(new remove_extent_t<T>[n]());
return std::unique_ptr<T>(new std::remove_extent_t<T>[n]());
}
template<typename T, class... Args>
@ -87,7 +188,7 @@ constexpr std::size_t size(const T (&array)[N]) noexcept {
// invoke_result_t, and so may not behave correctly when SFINAE is required
template <typename F>
class not_fn_result {
using DecayF = decay_t<F>;
using DecayF = std::decay_t<F>;
DecayF fn;
public:
explicit not_fn_result(F&& f) : fn(std::forward<F>(f)) {}
@ -96,23 +197,23 @@ class not_fn_result {
template<class... Args>
auto operator()(Args&&... args) &
-> decltype(!std::declval<result_of_t<DecayF&(Args...)>>()) {
-> decltype(!std::declval<std::result_of_t<DecayF&(Args...)>>()) {
return !fn(std::forward<Args>(args)...);
}
template<class... Args>
auto operator()(Args&&... args) const&
-> decltype(!std::declval<result_of_t<DecayF const&(Args...)>>()) {
-> decltype(!std::declval<std::result_of_t<DecayF const&(Args...)>>()) {
return !fn(std::forward<Args>(args)...);
}
template<class... Args>
auto operator()(Args&&... args) &&
-> decltype(!std::declval<result_of_t<DecayF(Args...)>>()) {
-> decltype(!std::declval<std::result_of_t<DecayF(Args...)>>()) {
return !std::move(fn)(std::forward<Args>(args)...);
}
template<class... Args>
auto operator()(Args&&... args) const&&
-> decltype(!std::declval<result_of_t<DecayF const(Args...)>>()) {
-> decltype(!std::declval<std::result_of_t<DecayF const(Args...)>>()) {
return !std::move(fn)(std::forward<Args>(args)...);
}
};
@ -128,10 +229,8 @@ constexpr in_place_t in_place{};
template<typename T>
struct in_place_type_t {};
#ifdef __cpp_variable_templates
template<typename T>
constexpr in_place_type_t<T> in_place_type{};
#endif // __cpp_variable_templates
} // namespace _backport17
namespace _backport_ts {
@ -186,11 +285,11 @@ private:
};
template <class CharT, class Traits, class DelimT>
ostream_joiner<decay_t<DelimT>, CharT, Traits>
ostream_joiner<std::decay_t<DelimT>, CharT, Traits>
make_ostream_joiner(std::basic_ostream<CharT, Traits>& os,
DelimT&& delimiter) {
return ostream_joiner<decay_t<DelimT>,
CharT, Traits>(os, std::forward<DelimT>(delimiter));
return ostream_joiner<std::decay_t<DelimT>,
CharT, Traits>(os, std::forward<DelimT>(delimiter));
}
} // namespace _backport_ts
@ -202,9 +301,7 @@ using _backport17::not_fn;
using _backport17::in_place_t;
using _backport17::in_place;
using _backport17::in_place_type_t;
#ifdef __cpp_variable_templates
using _backport17::in_place_type;
#endif // __cpp_variable_templates
using _backport_ts::ostream_joiner;
using _backport_ts::make_ostream_joiner;
} // namespace ceph

View File

@ -168,7 +168,7 @@ public:
template<typename T> const T get_val(const std::string &key) const;
template<typename T, typename Callback, typename...Args>
auto with_val(const string& key, Callback&& cb, Args&&... args) const ->
ceph::result_of_t<Callback(const T&, Args...)> {
std::result_of_t<Callback(const T&, Args...)> {
return std::forward<Callback>(cb)(
boost::get<T>(this->get_val_generic(key)),
std::forward<Args>(args)...);

View File

@ -46,38 +46,38 @@ namespace ceph {
// are some lock factories.
template<typename Mutex, typename ...Args>
inline auto uniquely_lock(Mutex&& m, Args&& ...args)
-> std::unique_lock<remove_reference_t<Mutex> > {
return std::unique_lock<remove_reference_t<Mutex> >(
-> std::unique_lock<std::remove_reference_t<Mutex> > {
return std::unique_lock<std::remove_reference_t<Mutex> >(
std::forward<Mutex>(m), std::forward<Args>(args)... );
}
template<typename Mutex, typename ...Args>
inline auto sharingly_lock(Mutex&& m, Args&& ...args)
-> boost::shared_lock<remove_reference_t<Mutex> > {
-> boost::shared_lock<std::remove_reference_t<Mutex> > {
return
boost::shared_lock<remove_reference_t<Mutex> >(
boost::shared_lock<std::remove_reference_t<Mutex> >(
std::forward<Mutex>(m), std::forward<Args>(args)...);
}
template<typename Mutex, typename ...Args>
inline auto shuniquely_lock(std::unique_lock<Mutex>&& m, Args&& ...args)
-> shunique_lock<remove_reference_t<Mutex> > {
return shunique_lock<remove_reference_t<Mutex> >(
-> shunique_lock<std::remove_reference_t<Mutex> > {
return shunique_lock<std::remove_reference_t<Mutex> >(
std::forward<std::unique_lock<Mutex> >(m), std::forward<Args>(args)...);
}
template<typename Mutex, typename ...Args>
inline auto shuniquely_lock(boost::shared_lock<Mutex>&& m, Args&& ...args)
-> shunique_lock<remove_reference_t<Mutex> > {
return shunique_lock<remove_reference_t<Mutex> >(
-> shunique_lock<std::remove_reference_t<Mutex> > {
return shunique_lock<std::remove_reference_t<Mutex> >(
std::forward<boost::shared_lock<Mutex> >(m),
std::forward<Args>(args)...);
}
template<typename Mutex, typename ...Args>
inline auto shuniquely_lock(Mutex&& m, Args&& ...args)
-> shunique_lock<remove_reference_t<Mutex> > {
return shunique_lock<remove_reference_t<Mutex> >(
-> shunique_lock<std::remove_reference_t<Mutex> > {
return shunique_lock<std::remove_reference_t<Mutex> >(
std::forward<Mutex>(m), std::forward<Args>(args)...);
}
@ -104,7 +104,7 @@ inline auto shuniquely_lock(Mutex&& m, Args&& ...args)
template<typename Mutex>
inline auto guardedly_lock(Mutex&& m)
-> std::lock_guard<remove_reference_t<Mutex> > {
-> std::lock_guard<std::remove_reference_t<Mutex> > {
m.lock();
// So the way this works is that Copy List Initialization creates
// one and only one Temporary. There is no implicit copy that is
@ -126,7 +126,7 @@ inline auto guardedly_lock(Mutex&& m)
template<typename Mutex>
inline auto guardedly_lock(Mutex&& m, std::adopt_lock_t)
-> std::lock_guard<remove_reference_t<Mutex> > {
-> std::lock_guard<std::remove_reference_t<Mutex> > {
return { std::forward<Mutex>(m), std::adopt_lock };
}
@ -156,11 +156,11 @@ inline auto with_shared_lock(Mutex&& mutex, Fun&& fun, Args&&... args)
// returns a lock class.
//
#define UNIQUE_LOCK_T(m) \
::std::unique_lock<ceph::remove_reference_t<decltype(m)>>
::std::unique_lock<std::remove_reference_t<decltype(m)>>
#define SHARED_LOCK_T(m) \
::std::shared_lock<ceph::remove_reference_t<decltype(m)>>
::std::shared_lock<std::remove_reference_t<decltype(m)>>
#define SHUNIQUE_LOCK_T(m) \
::ceph::shunique_lock<ceph::remove_reference_t<decltype(m)>>
::ceph::shunique_lock<std::remove_reference_t<decltype(m)>>
// boost::optional is wonderful! Unfortunately it lacks a function for
// the thing you would most obviously want to do with it: apply a
@ -176,7 +176,7 @@ inline auto with_shared_lock(Mutex&& mutex, Fun&& fun, Args&&... args)
//
template<typename T, typename F>
auto maybe_do(const boost::optional<T>& t, F&& f) ->
boost::optional<ceph::result_of_t<F(const ceph::decay_t<T>)>>
boost::optional<std::result_of_t<F(const std::decay_t<T>)>>
{
if (t)
return { std::forward<F>(f)(*t) };
@ -190,9 +190,9 @@ auto maybe_do(const boost::optional<T>& t, F&& f) ->
//
template<typename T, typename F, typename U>
auto maybe_do_or(const boost::optional<T>& t, F&& f, U&& u) ->
ceph::result_of_t<F(const ceph::decay_t<T>)>
std::result_of_t<F(const std::decay_t<T>)>
{
static_assert(std::is_convertible<U, ceph::result_of_t<F(T)>>::value,
static_assert(ceph::is_convertible_v<U, std::result_of_t<F(T)>>,
"Alternate value must be convertible to function return type.");
if (t)
return std::forward<F>(f)(*t);

View File

@ -85,12 +85,12 @@ class static_ptr {
//
template<typename T, std::size_t S>
constexpr static int create_ward() noexcept {
static_assert(std::is_void<Base>{} ||
std::is_base_of<Base, decay_t<T>>{},
static_assert(ceph::is_void_v<Base> ||
ceph::is_base_of_v<Base, std::decay_t<T>>,
"Value to store must be a derivative of the base.");
static_assert(S <= Size, "Value too large.");
static_assert(std::is_void<Base>{} || !std::is_const<Base>{} ||
std::is_const<T>{},
static_assert(ceph::is_void_v<Base> || !std::is_const<Base>{} ||
ceph::is_const_v<T>,
"Cannot assign const pointer to non-const pointer.");
return 0;
}
@ -134,13 +134,13 @@ public:
//
// Since the templated versions don't count for overriding the defaults
static_ptr(const static_ptr& rhs)
noexcept(std::is_nothrow_copy_constructible<Base>{}) : operate(rhs.operate) {
noexcept(ceph::is_nothrow_copy_constructible_v<Base>) : operate(rhs.operate) {
if (operate) {
operate(_mem::op::copy, &rhs.buf, &buf);
}
}
static_ptr(static_ptr&& rhs)
noexcept(std::is_nothrow_move_constructible<Base>{}) : operate(rhs.operate) {
noexcept(ceph::is_nothrow_move_constructible_v<Base>) : operate(rhs.operate) {
if (operate) {
operate(_mem::op::move, &rhs.buf, &buf);
}
@ -148,7 +148,7 @@ public:
template<typename U, std::size_t S>
static_ptr(const static_ptr<U, S>& rhs)
noexcept(std::is_nothrow_copy_constructible<U>{}) : operate(rhs.operate) {
noexcept(ceph::is_nothrow_copy_constructible_v<U>) : operate(rhs.operate) {
create_ward<U, S>();
if (operate) {
operate(_mem::op::copy, &rhs.buf, &buf);
@ -156,7 +156,7 @@ public:
}
template<typename U, std::size_t S>
static_ptr(static_ptr<U, S>&& rhs)
noexcept(std::is_nothrow_move_constructible<U>{}) : operate(rhs.operate) {
noexcept(ceph::is_nothrow_move_constructible_v<U>) : operate(rhs.operate) {
create_ward<U, S>();
if (operate) {
operate(_mem::op::move, &rhs.buf, &buf);
@ -164,7 +164,7 @@ public:
}
static_ptr& operator =(const static_ptr& rhs)
noexcept(std::is_nothrow_copy_constructible<Base>{}) {
noexcept(ceph::is_nothrow_copy_constructible_v<Base>) {
reset();
if (rhs) {
operate = rhs.operate;
@ -174,7 +174,7 @@ public:
return *this;
}
static_ptr& operator =(static_ptr&& rhs)
noexcept(std::is_nothrow_move_constructible<Base>{}) {
noexcept(ceph::is_nothrow_move_constructible_v<Base>) {
reset();
if (rhs) {
operate = rhs.operate;
@ -185,7 +185,7 @@ public:
template<typename U, std::size_t S>
static_ptr& operator =(const static_ptr<U, S>& rhs)
noexcept(std::is_nothrow_copy_constructible<U>{}) {
noexcept(ceph::is_nothrow_copy_constructible_v<U>) {
create_ward<U, S>();
reset();
if (rhs) {
@ -197,7 +197,7 @@ public:
}
template<typename U, std::size_t S>
static_ptr& operator =(static_ptr<U, S>&& rhs)
noexcept(std::is_nothrow_move_constructible<U>{}) {
noexcept(ceph::is_nothrow_move_constructible_v<U>) {
create_ward<U, S>();
reset();
if (rhs) {
@ -215,12 +215,12 @@ public:
//
template<typename T, typename... Args>
static_ptr(in_place_type_t<T>, Args&& ...args)
noexcept(std::is_nothrow_constructible<T, Args...>{})
noexcept(ceph::is_nothrow_constructible_v<T, Args...>)
: operate(&_mem::op_fun<T>){
static_assert((!std::is_nothrow_copy_constructible<Base>{} ||
std::is_nothrow_copy_constructible<T>{}) &&
(!std::is_nothrow_move_constructible<Base>{} ||
std::is_nothrow_move_constructible<T>{}),
static_assert((!ceph::is_nothrow_copy_constructible_v<Base> ||
ceph::is_nothrow_copy_constructible_v<T>) &&
(!ceph::is_nothrow_move_constructible_v<Base> ||
ceph::is_nothrow_move_constructible_v<T>),
"If declared type of static_ptr is nothrow "
"move/copy constructible, then any "
"type assigned to it must be as well. "
@ -238,7 +238,7 @@ public:
//
template<typename T, typename... Args>
void emplace(Args&& ...args)
noexcept(std::is_nothrow_constructible<T, Args...>{}) {
noexcept(ceph::is_nothrow_constructible_v<T, Args...>) {
create_ward<T, sizeof(T)>();
reset();
operate = &_mem::op_fun<T>;
@ -250,11 +250,11 @@ public:
return operate ? reinterpret_cast<Base*>(&buf) : nullptr;
}
template<typename U = Base>
enable_if_t<!std::is_void<U>{}, Base*> operator->() const noexcept {
std::enable_if_t<!ceph::is_void_v<U>, Base*> operator->() const noexcept {
return get();
}
template<typename U = Base>
enable_if_t<!std::is_void<U>{}, Base&> operator *() const noexcept {
std::enable_if_t<!ceph::is_void_v<U>, Base&> operator *() const noexcept {
return *get();
}
operator bool() const noexcept {
@ -401,7 +401,7 @@ static_ptr<U, Z> reinterpret_pointer_cast(static_ptr<T, S>&& p) {
// returns a null value rather than throwing.
template<typename U, std::size_t Z, typename T, std::size_t S>
static_ptr<U, Z> resize_pointer_cast(const static_ptr<T, S>& p) {
static_assert(std::is_same<U, T>{},
static_assert(ceph::is_same_v<U, T>,
"resize_pointer_cast only changes size, not type.");
static_ptr<U, Z> r;
if (Z >= p.operate(_mem::op::size, &p.buf, nullptr)) {
@ -412,7 +412,7 @@ static_ptr<U, Z> resize_pointer_cast(const static_ptr<T, S>& p) {
}
template<typename U, std::size_t Z, typename T, std::size_t S>
static_ptr<U, Z> resize_pointer_cast(static_ptr<T, S>&& p) {
static_assert(std::is_same<U, T>{},
static_assert(ceph::is_same_v<U, T>,
"resize_pointer_cast only changes size, not type.");
static_ptr<U, Z> r;
if (Z >= p.operate(_mem::op::size, &p.buf, nullptr)) {
@ -437,6 +437,6 @@ bool operator ==(std::nullptr_t, static_ptr<Base, Size> s) {
template<typename Base, typename Derived = Base,
std::size_t Size = sizeof(Derived), typename... Args>
static_ptr<Base, Size> make_static(Args&& ...args) {
return { in_place_type_t<Derived>{}, std::forward<Args>(args)... };
return { ceph::in_place_type<Derived>, std::forward<Args>(args)... };
}
}

View File

@ -17,11 +17,10 @@
#include <mutex>
#include <random>
#include <type_traits>
#include "boost/optional.hpp"
#include "common/backport14.h"
// Basic random number facility, adapted from N3551:
namespace ceph {
namespace util {
@ -145,7 +144,7 @@ IntegerT generate_random_number()
template <typename IntegerT>
IntegerT generate_random_number(const IntegerT min, const IntegerT max,
ceph::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
std::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
{
return detail::generate_random_number<IntegerT,
std::uniform_int_distribution<IntegerT>,
@ -158,7 +157,7 @@ namespace detail {
template <typename IntegerT, typename MutexT, typename EngineT>
int generate_random_number(const IntegerT min, const IntegerT max,
MutexT& m, EngineT& e,
ceph::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
std::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
{
return detail::generate_random_number<IntegerT, MutexT,
std::uniform_int_distribution<IntegerT>,
@ -169,7 +168,7 @@ int generate_random_number(const IntegerT min, const IntegerT max,
template <typename IntegerT, typename MutexT, typename EngineT>
int generate_random_number(const IntegerT max,
MutexT& m, EngineT& e,
ceph::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
std::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
{
constexpr IntegerT zero = 0;
return generate_random_number(zero, max, m, e);
@ -179,7 +178,7 @@ int generate_random_number(const IntegerT max,
template <typename IntegerT>
int generate_random_number(const IntegerT max,
ceph::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
std::enable_if_t<std::is_integral<IntegerT>::value>* = nullptr)
{
constexpr IntegerT zero = 0;
return generate_random_number(zero, max);
@ -187,7 +186,7 @@ int generate_random_number(const IntegerT max,
template <typename RealT>
RealT generate_random_number(const RealT min, const RealT max,
ceph::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
std::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
{
return detail::generate_random_number<RealT,
std::uniform_real_distribution<RealT>,
@ -199,7 +198,7 @@ namespace detail {
template <typename RealT, typename MutexT>
RealT generate_random_number(const RealT max, MutexT& m,
ceph::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
std::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
{
constexpr RealT zero = 0.0;
return generate_random_number(zero, max, m);
@ -207,7 +206,7 @@ RealT generate_random_number(const RealT max, MutexT& m,
template <typename RealT, typename MutexT, typename EngineT>
RealT generate_random_number(const RealT min, const RealT max, MutexT& m, EngineT& e,
ceph::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
std::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
{
return detail::generate_random_number<RealT, MutexT,
std::uniform_real_distribution<RealT>,
@ -218,7 +217,7 @@ RealT generate_random_number(const RealT min, const RealT max, MutexT& m, Engine
template <typename RealT, typename MutexT, typename EngineT>
RealT generate_random_number(const RealT max, MutexT& m, EngineT& e,
ceph::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
std::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
{
constexpr RealT zero = 0.0;
return generate_random_number(zero, max, m, e);
@ -228,7 +227,7 @@ RealT generate_random_number(const RealT max, MutexT& m, EngineT& e,
template <typename RealT>
RealT generate_random_number(const RealT max,
ceph::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
std::enable_if_t<std::is_floating_point<RealT>::value>* = nullptr)
{
constexpr RealT zero = 0.0;
return generate_random_number(zero, max);