Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::uses_allocator

      From cppreference.com
      <cpp‎ |memory
       
       
      Memory management library
      (exposition only*)
      Allocators
      Uninitialized memory algorithms
      Constrained uninitialized memory algorithms
      Memory resources
      Uninitialized storage(until C++20)
      (until C++20*)
      (until C++20*)
      Garbage collector support(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
       
      Defined in header<memory>
      template<class T,class Alloc>
      struct uses_allocator;
      (since C++11)

      IfT has a nested typeallocator_type which is convertible fromAlloc, the member constantvalue istrue. Otherwisevalue isfalse.

      Contents

      [edit]Helper variable template

      template<class T,class Alloc>
      constexprbool uses_allocator_v= uses_allocator<T, Alloc>::value;
      (since C++17)
      [edit]

      Inherited fromstd::integral_constant

      Member constants

      value
      [static]
      true ifT uses allocatorAlloc,false otherwise
      (public static member constant)

      Member functions

      operator bool
      converts the object tobool, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typebool
      typestd::integral_constant<bool, value>

      [edit]Uses-allocator construction

      There are three conventions of passing an allocatoralloc to a constructor of some typeT:

      • IfT does not use a compatible allocator (std::uses_allocator_v<T, Alloc> isfalse), thenalloc is ignored.
      • Otherwise,std::uses_allocator_v<T, Alloc> istrue, and
      • ifT uses theleading-allocator convention (is invocable asT(std::allocator_arg, alloc, args...)), then uses-allocator construction uses this form.
      • ifT uses thetrailing-allocator convention (is invocable asT(args..., alloc)), then uses-allocator construction uses this form.
      • Otherwise, the program is ill-formed (this meansstd::uses_allocator_v<T, Alloc> istrue, but the type does not follow either of the two allowed conventions).

      The utility functionsstd::make_obj_using_allocator, andstd::uninitialized_construct_using_allocator may be used to explicitly create an object following the above protocol, andstd::uses_allocator_construction_args can be used to prepare the argument list that matches the flavor of uses-allocator construction expected by the type.

      (since C++20)

      [edit]Specializations

      Given aprogram-defined typeT that does not have a nestedallocator_type, a program can specializestd::uses_allocator to derive fromstd::true_type forT if any of the following requirements is satisfied:

      • T has a constructor which takesstd::allocator_arg_t as the first argument, andAlloc as the second argument.
      • T has a constructor which takesAlloc as the last argument.

      In the above,Alloc is a type that satisfiesAllocator or is a pointer type convertible tostd::experimental::pmr::memory_resource*(library fundamentals TS).

      The following specializations are already provided by the standard library:

      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]
      specializes thestd::uses_allocator type trait
      (class template specialization)[edit]

      [edit]Notes

      This type trait is used bystd::tuple,std::scoped_allocator_adaptor, andstd::pmr::polymorphic_allocator. It may also be used by custom allocators or wrapper types to determine whether the object or member being constructed is itself capable of using an allocator (e.g. is a container), in which case an allocator should be passed to its constructor.

      [edit]See also

      a tag used to select allocator-aware constructors
      (tag)[edit]
      prepares the argument list matching the flavor of uses-allocator construction required by the given type
      (function template)[edit]
      creates an object of the given type by means of uses-allocator construction
      (function template)[edit]
      creates an object of the given type at specified memory location by means of uses-allocator construction
      (function template)[edit]
      implements multi-level allocator for multi-level containers
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/uses_allocator&oldid=176432"

      [8]ページ先頭

      ©2009-2025 Movatter.jp