libstdc++: alloc_traits.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30#ifndef _ALLOC_TRAITS_H

31#define _ALLOC_TRAITS_H 1

32

35#if __cplusplus >= 201103L

38# if _GLIBCXX_HOSTED

40# endif

41# if __cpp_exceptions

43# endif

44#endif

45

46namespace std _GLIBCXX_VISIBILITY(default)

47{

48_GLIBCXX_BEGIN_NAMESPACE_VERSION

49

50#if __cplusplus >= 201103L

51

52#pragma GCC diagnostic push

53#pragma GCC diagnostic ignored "-Wc++14-extensions"

54#pragma GCC diagnostic ignored "-Wc++17-extensions"

55

56

57 struct __allocator_traits_base

58 {

59#if __cpp_concepts

60 template<typename _Tp, typename _Up>

62 template<typename _Tp, typename _Up, typename = void>

64 struct __rebind : __replace_first_arg<_Tp, _Up>

66 static_assert(is_same<

67 typename __replace_first_arg<_Tp, typename _Tp::value_type>::type,

68 _Tp>::value,

69 "allocator_traits::rebind_alloc<A::value_type> must be A");

70 };

71

72 template<typename _Tp, typename _Up>

73#if __cpp_concepts

74 requires requires { typename _Tp::template rebind<_Up>::other; }

75 struct __rebind<_Tp, _Up>

76#else

77 struct __rebind<_Tp, _Up,

78 __void_t<typename _Tp::template rebind<_Up>::other>>

79#endif

80 {

81 using type = typename _Tp::template rebind<_Up>::other;

82

83 static_assert(is_same<

84 typename _Tp::template rebind<typename _Tp::value_type>::other,

85 _Tp>::value,

86 "allocator_traits::rebind_alloc<A::value_type> must be A");

87 };

88

89 protected:

90 template<typename _Tp>

91 using __pointer = typename _Tp::pointer;

92 template<typename _Tp>

93 using __c_pointer = typename _Tp::const_pointer;

94 template<typename _Tp>

95 using __v_pointer = typename _Tp::void_pointer;

96 template<typename _Tp>

97 using __cv_pointer = typename _Tp::const_void_pointer;

98 template<typename _Tp>

99 using __pocca = typename _Tp::propagate_on_container_copy_assignment;

100 template<typename _Tp>

101 using __pocma = typename _Tp::propagate_on_container_move_assignment;

102 template<typename _Tp>

103 using __pocs = typename _Tp::propagate_on_container_swap;

104 template<typename _Tp>

105 using __equal = __type_identity<typename _Tp::is_always_equal>;

106

107

108#if __cpp_concepts

109 template<typename _Alloc, typename _Sz, typename _Vp>

110 static constexpr bool __has_allocate_hint

111 = requires (_Alloc& __a, _Sz __n, _Vp __hint) {

112 __a.allocate(__n, __hint);

113 };

114#else

115 template<typename _Alloc, typename _Sz, typename _Vp>

116 using __allocate_hint_t

117 = decltype(std::declval<_Alloc&>()

118 .allocate(std::declval<_Sz>(), std::declval<_Vp>()));

119 template<typename _Alloc, typename _Sz, typename _Vp, typename = void>

120 static constexpr bool __has_allocate_hint = false;

121 template<typename _Alloc, typename _Sz, typename _Vp>

122 static constexpr bool

123 __has_allocate_hint<_Alloc, _Sz, _Vp,

124 __void_t<__allocate_hint_t<_Alloc, _Sz, _Vp>>>

125 = true;

126#endif

127

128

129

130

131

132#if __cpp_concepts

133 template<typename _Alloc, typename _Tp, typename... _Args>

134 static constexpr bool __has_construct

135 = requires (_Alloc& __a, _Tp* __p, _Args&&... __args) {

136 __a.construct(__p, std::forward<_Args>(__args)...);

137 };

138 template<typename _Tp, typename... _Args>

139 static constexpr bool __can_construct_at

140 = requires (_Tp* __p, _Args&&... __args) {

141#if __cpp_constexpr_dynamic_alloc

142 std::construct_at(__p, std::forward<_Args>(__args)...);

143#else

144 ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);

145#endif

146 };

147 template<typename _Alloc, typename _Tp, typename... _Args>

148 static constexpr bool __can_construct

149 = __has_construct<_Alloc, _Tp, _Args...>

150 || __can_construct_at<_Tp, _Args...>;

151#else

152 template<typename _Alloc, typename _Tp, typename... _Args>

153 using __construct_t

154 = decltype(std::declval<_Alloc&>().construct(std::declval<_Tp*>(),

155 std::declval<_Args>()...));

156 template<typename _Alloc, typename _Tp, typename, typename... _Args>

157 static constexpr bool __has_construct_impl = false;

158 template<typename _Alloc, typename _Tp, typename... _Args>

159 static constexpr bool

160 __has_construct_impl<_Alloc, _Tp,

161 __void_t<__construct_t<_Alloc, _Tp, _Args...>>,

162 _Args...>

163 = true;

164 template<typename _Alloc, typename _Tp, typename... _Args>

165 static constexpr bool __has_construct

166 = __has_construct_impl<_Alloc, _Tp, void, _Args...>;

167 template<typename _Tp, typename... _Args>

168 using __new_expr_t

169 = decltype(::new((void*)0) _Tp(std::declval<_Args>()...));

170 template<typename _Tp, typename, typename... _Args>

171 static constexpr bool __has_new_expr = false;

172 template<typename _Tp, typename... _Args>

173 static constexpr bool

174 __has_new_expr<_Tp, __void_t<__new_expr_t<_Tp, _Args...>>, _Args...>

175 = true;

176 template<typename _Alloc, typename _Tp, typename... _Args>

177 static constexpr bool __can_construct

178 = __has_construct<_Alloc, _Tp, _Args...>

179 || __has_new_expr<_Tp, void, _Args...>;

180#endif

181

182

183#if __cpp_concepts

184 template<typename _Alloc, typename _Tp>

185 static constexpr bool __has_destroy = requires (_Alloc& __a, _Tp* __p) {

186 __a.destroy(__p);

187 };

188#else

189 template<typename _Alloc, typename _Tp>

190 using __destroy_t

191 = decltype(std::declval<_Alloc&>().destroy(std::declval<_Tp*>()));

192 template<typename _Alloc, typename _Tp, typename = void>

193 static constexpr bool __has_destroy = false;

194 template<typename _Alloc, typename _Tp>

195 static constexpr bool __has_destroy<_Alloc, _Tp,

196 __void_t<__destroy_t<_Alloc, _Tp>>>

197 = true;

198#endif

199

200

201#if __cpp_concepts

202 template<typename _Alloc>

203 static constexpr bool __has_max_size = requires (const _Alloc& __a) {

204 __a.max_size();

205 };

206#else

207 template<typename _Alloc>

208 using __max_size_t = decltype(std::declval<const _Alloc&>().max_size());

209 template<typename _Alloc, typename = void>

210 static constexpr bool __has_max_size = false;

211 template<typename _Alloc>

212 static constexpr bool __has_max_size<_Alloc,

213 __void_t<__max_size_t<_Alloc>>>

214 = true;

215#endif

216

217

218

219#if __cpp_concepts

220 template<typename _Alloc>

221 static constexpr bool __has_soccc = requires (const _Alloc& __a) {

222 __a.select_on_container_copy_construction();

223 };

224#else

225 template<typename _Alloc>

226 using __soccc_t

227 = decltype(std::declval<const _Alloc&>()

228 .select_on_container_copy_construction());

229 template<typename _Alloc, typename = void>

230 static constexpr bool __has_soccc = false;

231 template<typename _Alloc>

232 static constexpr bool __has_soccc<_Alloc, __void_t<__soccc_t<_Alloc>>>

233 = true;

234#endif

235 };

236

237 template<typename _Alloc, typename _Up>

238 using __alloc_rebind

239 = typename __allocator_traits_base::template __rebind<_Alloc, _Up>::type;

240

241

242

243

244

245

246

247

248 template<typename _Alloc>

250 {

251

253

255

256

257

258

259

260

261 using pointer = __detected_or_t<value_type*, __pointer, _Alloc>;

262

263 private:

264

265 template<template<typename> class _Func, typename _Tp, typename = void>

266 struct _Ptr

267 {

269 };

270

271 template<template<typename> class _Func, typename _Tp>

272 struct _Ptr<_Func, _Tp, __void_t<_Func<_Alloc>>>

273 {

274 using type = _Func<_Alloc>;

275 };

276

277

278 template<typename _A2, typename _PtrT, typename = void>

279 struct _Diff

280 { using type = typename pointer_traits<_PtrT>::difference_type; };

281

282 template<typename _A2, typename _PtrT>

283 struct _Diff<_A2, _PtrT, __void_t<typename _A2::difference_type>>

284 { using type = typename _A2::difference_type; };

285

286

287 template<typename _A2, typename _DiffT, typename = void>

288 struct _Size : make_unsigned<_DiffT> { };

289

290 template<typename _A2, typename _DiffT>

291 struct _Size<_A2, _DiffT, __void_t<typename _A2::size_type>>

292 { using type = typename _A2::size_type; };

293

294 public:

295

296

297

298

299

300

301 using const_pointer = typename _Ptr<__c_pointer, const value_type>::type;

302

303

304

305

306

307

308

309 using void_pointer = typename _Ptr<__v_pointer, void>::type;

310

311

312

313

314

315

316

318

319

320

321

322

323

324

326

327

328

329

330

331

332

333 using size_type = typename _Size<_Alloc, difference_type>::type;

334

335

336

337

338

339

340

342 = __detected_or_t<false_type, __pocca, _Alloc>;

343

344

345

346

347

348

349

351 = __detected_or_t<false_type, __pocma, _Alloc>;

352

353

354

355

356

357

358

360 = __detected_or_t<false_type, __pocs, _Alloc>;

361

362

363

364

365

366

367

369 = typename __detected_or_t<is_empty<_Alloc>, __equal, _Alloc>::type;

370

371 template<typename _Tp>

372 using rebind_alloc = __alloc_rebind<_Alloc, _Tp>;

373 template<typename _Tp>

375

376

377

378

379

380

381

382

383 _GLIBCXX_NODISCARD static _GLIBCXX20_CONSTEXPR pointer

385 { return __a.allocate(__n); }

386

387

388

389

390

391

392

393

394

395

396

397

398 _GLIBCXX_NODISCARD static _GLIBCXX20_CONSTEXPR pointer

400 {

401 if constexpr (__has_allocate_hint<_Alloc, size_type, const_void_pointer>)

402 return __a.allocate(__n, __hint);

403 else

404 return __a.allocate(__n);

405 }

406

407

408

409

410

411

412

413

414

415 static _GLIBCXX20_CONSTEXPR void

417 { __a.deallocate(__p, __n); }

418

419

420

421

422

423

424

425

426

427

428

429

430 template<typename _Tp, typename... _Args>

431#if __cpp_concepts && __cpp_constexpr_dynamic_alloc

432 requires __can_construct<_Alloc, _Tp, _Args...>

433 static constexpr void

434#else

435 static __enable_if_t<__can_construct<_Alloc, _Tp, _Args...>>

436#endif

437 construct(_Alloc& __a, _Tp* __p, _Args&&... __args)

438 noexcept(_S_nothrow_construct<_Tp, _Args...>())

439 {

440 if constexpr (__has_construct<_Alloc, _Tp, _Args...>)

441 __a.construct(__p, std::forward<_Args>(__args)...);

442 else

444 }

445

446

447

448

449

450

451

452

453

454 template<typename _Tp>

455 static _GLIBCXX20_CONSTEXPR void

457 noexcept(_S_nothrow_destroy<_Tp>())

458 {

459 if constexpr (__has_destroy<_Alloc, _Tp>)

460 __a.destroy(__p);

461 else

463 }

464

465

466

467

468

469

470

471

472

473 static _GLIBCXX20_CONSTEXPR size_type

475 {

476 if constexpr (__has_max_size<_Alloc>)

477 return __a.max_size();

478 else

479

480

481 return __gnu_cxx::__numeric_traits<size_type>::__max

483 }

484

485

486

487

488

489

490

491

492

493 static _GLIBCXX20_CONSTEXPR _Alloc

495 {

496 if constexpr (__has_soccc<_Alloc>)

497 return __rhs.select_on_container_copy_construction();

498 else

499 return __rhs;

500 }

501

502 private:

503#if __cpp_constexpr >= 201304

504 template<typename _Tp, typename... _Args>

505 static constexpr bool

506 _S_nothrow_construct(_Alloc* __a = nullptr, _Tp* __p = nullptr)

507 {

508 if constexpr (__has_construct<_Alloc, _Tp, _Args...>)

509 return noexcept(__a->construct(__p, std::declval<_Args>()...));

510 else

511 return __is_nothrow_new_constructible<_Tp, _Args...>;

512 }

513

514 template<typename _Tp>

515 static constexpr bool

516 _S_nothrow_destroy(_Alloc* __a = nullptr, _Tp* __p = nullptr)

517 {

518 if constexpr (__has_destroy<_Alloc, _Tp>)

519 return noexcept(__a->destroy(__p));

520 else

521 return is_nothrow_destructible<_Tp>::value;

522 }

523#else

524 template<typename _Tp, typename... _Args>

525 static constexpr

526 __enable_if_t<__has_construct<_Alloc, _Tp, _Args...>, bool>

527 _S_nothrow_construct(_Alloc* __a = nullptr, _Tp* __p = nullptr)

528 { return noexcept(__a->construct(__p, std::declval<_Args>()...)); }

529

530 template<typename _Tp, typename... _Args>

531 static constexpr

532 __enable_if_t<!__has_construct<_Alloc, _Tp, _Args...>, bool>

533 _S_nothrow_construct(_Alloc* = nullptr, _Tp* __p = nullptr)

534 { return __is_nothrow_new_constructible<_Tp, _Args...>; }

535

536 template<typename _Tp>

537 static constexpr

538 __enable_if_t<__has_destroy<_Alloc, _Tp>, bool>

539 _S_nothrow_destroy(_Alloc* __a = nullptr, _Tp* __p = nullptr)

540 { return noexcept(__a->destroy(__p)); }

541

542 template<typename _Tp>

543 static constexpr

544 __enable_if_t<!__has_destroy<_Alloc, _Tp>, bool>

545 _S_nothrow_destroy(_Alloc* = nullptr, _Tp* __p = nullptr)

546 { return is_nothrow_destructible<_Tp>::value; }

547#endif

548 };

549#pragma GCC diagnostic pop

550

551#if _GLIBCXX_HOSTED

552

553

554

555

556

557

558

559 template<typename _Tp>

561 {

562

564

565

567

568

570

571

573

574

576

577

579

580

582

583

585

586

588

589

591

592

594

595

597

598 template<typename _Up>

600

601 template<typename _Up>

603

604

605

606

607

608

609

610

611 [[__nodiscard__,__gnu__::__always_inline__]]

612 static _GLIBCXX20_CONSTEXPR pointer

614 { return __a.allocate(__n); }

615

616

617

618

619

620

621

622

623

624

625

626 [[__nodiscard__,__gnu__::__always_inline__]]

627 static _GLIBCXX20_CONSTEXPR pointer

630 {

631#if __cplusplus <= 201703L

632 return __a.allocate(__n, __hint);

633#else

634 return __a.allocate(__n);

635#endif

636 }

637

638

639

640

641

642

643

644

645

646 [[__gnu__::__always_inline__]]

647 static _GLIBCXX20_CONSTEXPR void

649 { __a.deallocate(__p, __n); }

650

651

652

653

654

655

656

657

658

659

660

661

662 template<typename _Up, typename... _Args>

663 [[__gnu__::__always_inline__]]

664 static _GLIBCXX20_CONSTEXPR void

666 _Up* __p, _Args&&... __args)

667#if __cplusplus <= 201703L

668 noexcept(noexcept(__a.construct(__p, std::forward<_Args>(__args)...)))

669#else

670 noexcept(__is_nothrow_new_constructible<_Up, _Args...>)

671#endif

672 {

673#if __cplusplus <= 201703L

674 __a.construct(__p, std::forward<_Args>(__args)...);

675#elif __cpp_constexpr_dynamic_alloc

676 std::construct_at(__p, std::forward<_Args>(__args)...);

677#else

679#endif

680 }

681

682

683

684

685

686

687

688

689 template<typename _Up>

690 [[__gnu__::__always_inline__]]

691 static _GLIBCXX20_CONSTEXPR void

694 {

695#if __cplusplus <= 201703L

696 __a.destroy(__p);

697#else

698 std::destroy_at(__p);

699#endif

700 }

701

702

703

704

705

706

707 [[__gnu__::__always_inline__]]

708 static _GLIBCXX20_CONSTEXPR size_type

710 {

711#if __cplusplus <= 201703L

712 return __a.max_size();

713#else

714 return size_t(-1) / sizeof(value_type);

715#endif

716 }

717

718

719

720

721

722

723 [[__gnu__::__always_inline__]]

726 { return __rhs; }

727 };

728

729

730

731

732

733

734

735

736 template<>

738 {

739

741

742

744

745

747

748

750

751

753

754

756

757

759

760

762

763

765

766

768

769

771

772

774

775 template<typename _Up>

777

778 template<typename _Up>

780

781

782 static void*

784

785

786 static void

788

789

790

791

792

793

794

795

796

797

798

799

800 template<typename _Up, typename... _Args>

801 [[__gnu__::__always_inline__]]

802 static _GLIBCXX20_CONSTEXPR void

804 noexcept(__is_nothrow_new_constructible<_Up, _Args...>)

805 { std::_Construct(__p, std::forward<_Args>(__args)...); }

806

807

808

809

810

811

812

813

814 template<typename _Up>

815 [[__gnu__::__always_inline__]]

816 static _GLIBCXX20_CONSTEXPR void

820

821

824

825

826

827

828

829

830 [[__gnu__::__always_inline__]]

833 { return __rhs; }

834 };

835#endif

836

837

838#if __cplusplus < 201703L

839 template<typename _Alloc>

840 [[__gnu__::__always_inline__]]

841 inline void

842 __do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type)

843 { __one = __two; }

844

845 template<typename _Alloc>

846 [[__gnu__::__always_inline__]]

847 inline void

848 __do_alloc_on_copy(_Alloc&, const _Alloc&, false_type)

849 { }

850#endif

851

852 template<typename _Alloc>

853 [[__gnu__::__always_inline__]]

854 _GLIBCXX14_CONSTEXPR inline void

855 __alloc_on_copy(_Alloc& __one, const _Alloc& __two)

856 {

857 using __traits = allocator_traits<_Alloc>;

858 using __pocca =

859 typename __traits::propagate_on_container_copy_assignment::type;

860#if __cplusplus >= 201703L

861 if constexpr (__pocca::value)

862 __one = __two;

863#else

864 __do_alloc_on_copy(__one, __two, __pocca());

865#endif

866 }

867

868 template<typename _Alloc>

869 [[__gnu__::__always_inline__]]

870 constexpr _Alloc

871 __alloc_on_copy(const _Alloc& __a)

872 {

873 typedef allocator_traits<_Alloc> __traits;

874 return __traits::select_on_container_copy_construction(__a);

875 }

876

877#if __cplusplus < 201703L

878 template<typename _Alloc>

879 [[__gnu__::__always_inline__]]

880 inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, true_type)

882

883 template<typename _Alloc>

884 [[__gnu__::__always_inline__]]

885 inline void __do_alloc_on_move(_Alloc&, _Alloc&, false_type)

886 { }

887#endif

888

889 template<typename _Alloc>

890 [[__gnu__::__always_inline__]]

891 _GLIBCXX14_CONSTEXPR inline void

892 __alloc_on_move(_Alloc& __one, _Alloc& __two)

893 {

894 using __traits = allocator_traits<_Alloc>;

895 using __pocma

896 = typename __traits::propagate_on_container_move_assignment::type;

897#if __cplusplus >= 201703L

898 if constexpr (__pocma::value)

900#else

901 __do_alloc_on_move(__one, __two, __pocma());

902#endif

903 }

904

905#if __cplusplus < 201703L

906 template<typename _Alloc>

907 [[__gnu__::__always_inline__]]

908 inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, true_type)

909 {

910 using std::swap;

911 swap(__one, __two);

912 }

913

914 template<typename _Alloc>

915 [[__gnu__::__always_inline__]]

916 inline void __do_alloc_on_swap(_Alloc&, _Alloc&, false_type)

917 { }

918#endif

919

920 template<typename _Alloc>

921 [[__gnu__::__always_inline__]]

922 _GLIBCXX14_CONSTEXPR inline void

923 __alloc_on_swap(_Alloc& __one, _Alloc& __two)

924 {

925 using __traits = allocator_traits<_Alloc>;

926 using __pocs = typename __traits::propagate_on_container_swap::type;

927#if __cplusplus >= 201703L

928 if constexpr (__pocs::value)

929 {

930 using std::swap;

931 swap(__one, __two);

932 }

933#else

934 __do_alloc_on_swap(__one, __two, __pocs());

935#endif

936 }

937

938 template<typename _Alloc, typename _Tp,

939 typename _ValueT = __remove_cvref_t<typename _Alloc::value_type>,

940 typename = void>

941 struct __is_alloc_insertable_impl

943 { };

944

945 template<typename _Alloc, typename _Tp, typename _ValueT>

946 struct __is_alloc_insertable_impl<_Alloc, _Tp, _ValueT,

947 __void_t<decltype(allocator_traits<_Alloc>::construct(

948 std::declval<_Alloc&>(), std::declval<_ValueT*>(),

949 std::declval<_Tp>()))>>

951 { };

952

953

954

955

956 template<typename _Alloc>

957 struct __is_copy_insertable

958 : __is_alloc_insertable_impl<_Alloc,

959 typename _Alloc::value_type const&>::type

960 { };

961

962#if _GLIBCXX_HOSTED

963

964 template<typename _Tp>

965 struct __is_copy_insertable<allocator<_Tp>>

966 : is_copy_constructible<_Tp>

967 { };

968#endif

969

970

971

972

973 template<typename _Alloc>

974 struct __is_move_insertable

975 : __is_alloc_insertable_impl<_Alloc, typename _Alloc::value_type>::type

976 { };

977

978#if _GLIBCXX_HOSTED

979

980 template<typename _Tp>

981 struct __is_move_insertable<allocator<_Tp>>

982 : is_move_constructible<_Tp>

983 { };

984#endif

985

986

987 template<typename _Alloc, typename = void>

988 struct __is_allocator : false_type { };

989

990 template<typename _Alloc>

991 struct __is_allocator<_Alloc,

992 __void_t<typename _Alloc::value_type,

993 decltype(std::declval<_Alloc&>().allocate(size_t{}))>>

995

996 template<typename _Alloc>

997 using _RequireAllocator

998 = typename enable_if<__is_allocator<_Alloc>::value, _Alloc>::type;

999

1000 template<typename _Alloc>

1001 using _RequireNotAllocator

1002 = typename enable_if<!__is_allocator<_Alloc>::value, _Alloc>::type;

1003

1004#if __cpp_concepts >= 201907L

1005 template<typename _Alloc>

1006 concept __allocator_like = requires (_Alloc& __a) {

1007 typename _Alloc::value_type;

1008 __a.deallocate(__a.allocate(1u), 1u);

1009 };

1010#endif

1011

1012#endif

1013

1014

1015

1016

1017 template<typename _Alloc, bool = __is_empty(_Alloc)>

1018 struct __alloc_swap

1019 { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } };

1020

1021 template<typename _Alloc>

1022 struct __alloc_swap<_Alloc, false>

1023 {

1024 static void

1025 _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT

1026 {

1027

1028 if (__one != __two)

1029 swap(__one, __two);

1030 }

1031 };

1032

1033#if __cplusplus >= 201103L

1034 template<typename _Tp, bool

1035 = __or_<is_copy_constructible<typename _Tp::value_type>,

1036 is_nothrow_move_constructible<typename _Tp::value_type>>::value>

1037 struct __shrink_to_fit_aux

1038 { static bool _S_do_it(_Tp&) noexcept { return false; } };

1039

1040 template<typename _Tp>

1041 struct __shrink_to_fit_aux<_Tp, true>

1042 {

1043 _GLIBCXX20_CONSTEXPR

1044 static bool

1045 _S_do_it(_Tp& __c) noexcept

1046 {

1047#if __cpp_exceptions

1048 try

1049 {

1050 _Tp(__make_move_if_noexcept_iterator(__c.begin()),

1051 __make_move_if_noexcept_iterator(__c.end()),

1052 __c.get_allocator()).swap(__c);

1053 return true;

1054 }

1055 catch(...)

1056 { return false; }

1057#else

1058 return false;

1059#endif

1060 }

1061 };

1062#endif

1063

1064

1065

1066

1067

1068

1069

1070 template<typename _ForwardIterator, typename _Allocator>

1071 _GLIBCXX20_CONSTEXPR

1072 void

1073 _Destroy(_ForwardIterator __first, _ForwardIterator __last,

1074 _Allocator& __alloc)

1075 {

1076 for (; __first != __last; ++__first)

1077#if __cplusplus < 201103L

1079#else

1082#endif

1083 }

1084

1085#if _GLIBCXX_HOSTED

1086 template<typename _ForwardIterator, typename _Tp>

1087 __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR

1088 inline void

1089 _Destroy(_ForwardIterator __first, _ForwardIterator __last,

1090 allocator<_Tp>&)

1091 {

1093 }

1094#endif

1095

1096

1097

1098_GLIBCXX_END_NAMESPACE_VERSION

1099}

1100#endif

__bool_constant< true > true_type

The type used as a compile-time boolean with true value.

__bool_constant< false > false_type

The type used as a compile-time boolean with false value.

constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept

Convert a value to an rvalue.

constexpr _Tp * __addressof(_Tp &__r) noexcept

Same as C++11 std::addressof.

ISO C++ entities toplevel namespace is std.

constexpr void _Construct(_Tp *__p, _Args &&... __args)

constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last)

Uniform interface to all allocator types.

static constexpr void construct(_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(_S_nothrow_construct< _Tp, _Args... >())

Construct an object of type _Tp

__detected_or_t< false_type, __pocma, _Alloc > propagate_on_container_move_assignment

How the allocator is propagated on move assignment.

typename _Ptr< __v_pointer, void >::type void_pointer

The allocator's void pointer type.

__detected_or_t< value_type *, __pointer, _Alloc > pointer

The allocator's pointer type.

static constexpr pointer allocate(_Alloc &__a, size_type __n)

Allocate memory.

static constexpr pointer allocate(_Alloc &__a, size_type __n, const_void_pointer __hint)

Allocate memory.

typename _Size< _Alloc, difference_type >::type size_type

The allocator's size type.

typename _Ptr< __cv_pointer, const void >::type const_void_pointer

The allocator's const void pointer type.

static constexpr void destroy(_Alloc &__a, _Tp *__p) noexcept(_S_nothrow_destroy< _Tp >())

Destroy an object of type _Tp.

typename _Diff< _Alloc, pointer >::type difference_type

The allocator's difference type.

typename _Ptr< __c_pointer, const value_type >::type const_pointer

The allocator's const pointer type.

_Alloc::value_type value_type

The allocated type.

static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)

Deallocate memory.

typename __detected_or_t< is_empty< _Alloc >, __equal, _Alloc >::type is_always_equal

Whether all instances of the allocator type compare equal.

static constexpr size_type max_size(const _Alloc &__a) noexcept

The maximum supported allocation size.

__detected_or_t< false_type, __pocca, _Alloc > propagate_on_container_copy_assignment

How the allocator is propagated on copy assignment.

static constexpr _Alloc select_on_container_copy_construction(const _Alloc &__rhs)

Obtain an allocator to use when copying a container.

__detected_or_t< false_type, __pocs, _Alloc > propagate_on_container_swap

How the allocator is propagated on swap.

_Alloc allocator_type

The allocator type.

allocator< _Tp > allocator_type

The allocator type.

static constexpr void construct(allocator_type &__a, _Up *__p, _Args &&... __args) noexcept(__is_nothrow_new_constructible< _Up, _Args... >)

Construct an object of type _Up

void * void_pointer

The allocator's void pointer type.

_Tp * pointer

The allocator's pointer type.

false_type propagate_on_container_swap

How the allocator is propagated on swap.

static constexpr pointer allocate(allocator_type &__a, size_type __n)

Allocate memory.

_Tp value_type

The allocated type.

static constexpr pointer allocate(allocator_type &__a, size_type __n, const_void_pointer __hint)

Allocate memory.

std::ptrdiff_t difference_type

The allocator's difference type.

true_type is_always_equal

Whether all instances of the allocator type compare equal.

const _Tp * const_pointer

The allocator's const pointer type.

const void * const_void_pointer

The allocator's const void pointer type.

true_type propagate_on_container_move_assignment

How the allocator is propagated on move assignment.

static constexpr void deallocate(allocator_type &__a, pointer __p, size_type __n)

Deallocate memory.

static constexpr size_type max_size(const allocator_type &__a) noexcept

The maximum supported allocation size.

static constexpr allocator_type select_on_container_copy_construction(const allocator_type &__rhs)

Obtain an allocator to use when copying a container.

static constexpr void destroy(allocator_type &__a, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)

Destroy an object of type _Up.

false_type propagate_on_container_copy_assignment

How the allocator is propagated on copy assignment.

std::size_t size_type

The allocator's size type.

false_type propagate_on_container_copy_assignment

How the allocator is propagated on copy assignment.

void * pointer

The allocator's pointer type.

void * void_pointer

The allocator's void pointer type.

static void deallocate(allocator_type &, void *, size_type)=delete

deallocate is ill-formed for allocator

true_type is_always_equal

Whether all instances of the allocator type compare equal.

void value_type

The allocated type.

static size_type max_size(const allocator_type &)=delete

max_size is ill-formed for allocator

std::size_t size_type

The allocator's size type.

true_type propagate_on_container_move_assignment

How the allocator is propagated on move assignment.

const void * const_pointer

The allocator's const pointer type.

std::ptrdiff_t difference_type

The allocator's difference type.

static void * allocate(allocator_type &, size_type, const void *=nullptr)=delete

allocate is ill-formed for allocator

static constexpr allocator_type select_on_container_copy_construction(const allocator_type &__rhs)

Obtain an allocator to use when copying a container.

static constexpr void construct(allocator_type &, _Up *__p, _Args &&... __args) noexcept(__is_nothrow_new_constructible< _Up, _Args... >)

Construct an object of type _Up

const void * const_void_pointer

The allocator's const void pointer type.

static constexpr void destroy(allocator_type &, _Up *__p) noexcept(is_nothrow_destructible< _Up >::value)

Destroy an object of type _Up

false_type propagate_on_container_swap

How the allocator is propagated on swap.

The standard allocator, as per C++03 [20.4.1].

Uniform interface to all pointer-like types.