テンプレートパラメータでアロケータを検出する「十分に」信頼できる方法はありますか? つまり、is_allocator
で使用できる型特性のようなものが必要ですenable_if
:
クラス テンプレートfuture (テンプレート パラメータ T を使用)があるとします。
// Default ctor with allocator
template <class Alloc, class... Args
class Enable = typename std::enable_if<
is_allocator<Alloc>::value
and std::is_constructible<T, Args...>::value
>::type
>
future(const Alloc& a, Args&&... args)
: _shared_value(std::allocate_shared<T>(a, std::forward<T>(args...))
{
}
// Default ctor (without allocator)
template <class... Args
class Enable = typename std::enable_if<
std::is_constructible<T, Args...>::value
>::type
>
future(Args&&... args)
: _shared_value(std::make_shared<T>(std::forward<T>(args...))
{
}
ここで_shared_value
は、std::shared_pointer<T>
です。