I http://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor/constructstd :: scoped_allocator_adaptor und eine Klasse mit einem Konstruktor std :: allocator_arg_t
wenn
std::uses_allocator<T, inner_allocator_type>::value==true
einige Worte hier finden (die Art T verwendet Verteilern, zum Beispiel ist es, einen Behälter)und wenn
std::is_constructible<T, std::allocator_arg_t, inner_allocator_type, Args...>::value==true
,ruft dann
std::allocator_traits<OUTERMOST>::construct(OUTERMOST(*this), p, std::allocator_arg, inner_allocator(), std::forward<Args>(args)...);
Also, ich habe einen einfachen Test
struct use_arg {
template <typename Alloc>
use_arg(std::allocator_arg_t, Alloc &, int i)
{ std::cout << i << " in use_arg()\n"; }
};
namespace std {
template <typename A> struct uses_allocator<use_arg, A>: true_type {};
} // namespace std
void test_scoped()
{
std::scoped_allocator_adaptor<std::allocator<use_arg>> sa;
auto p = sa.allocate(1);
sa.construct(p, 4);
sa.destroy(p);
sa.deallocate(p, 1);
}
aber gcc und Klirren geben Sie mir diese Fehler https://gist.github.com/anonymous/3e72754a7615162280fb
ich auch use_a
schreiben use_arg
zu ersetzen. Es könnte erfolgreich ausgeführt werden.
struct use_a {
template <typename Alloc>
use_a(int i, Alloc &) { std::cout << i << " in use_a()\n"; }
};
Was bewirkt diese Verhaltensweisen?
Was ist mit 'std :: ist_konstruierbar >> :: value'? Es ist auch "falsch", könnte aber konstruiert werden. –
linux40
@ linux40 das sieht wie ein Fehler aus, da zum Beispiel in clang, gibt es keine Überprüfung, nur uses_allocator :: value ist aktiviert. – ForEveR
gibt es nur einen Check in gcc auch. – ForEveR