A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/memory/uses_allocator/ below:

class template

<memory>

std::uses_allocator
template <class T, class Alloc> struct uses_allocator;

Uses allocator


Trait class that identifies whether T accepts an allocator convertible from Alloc.

It inherits from integral_constant as being either true_type or false_type, depending on whether T accepts such allocator.

The unspecialized definition for this template inherits from true_type if T::allocator_type exists and is_convertible<Alloc,T::allocator_type>::value is not false.

Classes that do not fill this requirement but still use an allocator shall specialize this template to derive from true_type if either:



Template parameters
T
A type.
Alloc
An allocator type.

Member types Inherited from integral_constant:

Member constants Inherited from integral_constant:
member constant definition value either true or false
Member functions Inherited from integral_constant:
operator bool
Returns value (public member function)

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// uses_allocator example
#include <iostream>
#include <memory>
#include <vector>

int main() {
  typedef std::vector<int> Container;
  typedef std::allocator<int> Allocator;

  if (std::uses_allocator<Container,Allocator>::value) {
    Allocator alloc;
    Container foo (5,10,alloc);
    for (auto x:foo) std::cout << x << ' ';
  }
  std::cout << '\n';
  return 0;
}

Output:


See also
allocator_traits
Allocator traits (class template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4