8#ifndef INCLUDED_BSLSTL_PRIORITYQUEUE
9#define INCLUDED_BSLSTL_PRIORITYQUEUE
377#include <bslscm_version.h>
408#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
409# define BSLSTL_PRIORITY_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T) \
410 requires ::BloombergLP::bslmf::ContainerCompatibleRange<R, T>
412# define BSLSTL_PRIORITY_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T)
415#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
421# define COMPILING_BSLSTL_PRIORITYQUEUE_H
423# undef COMPILING_BSLSTL_PRIORITYQUEUE_H
443template <
class VALUE,
444 class CONTAINER = vector<VALUE>,
445 class COMPARATOR = std::less<typename CONTAINER::value_type> >
448#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
458 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
464 template <
class INPUT_ITER,
class SENTINEL>
465 void privatePushRange(INPUT_ITER first, SENTINEL last);
490 BloombergLP::bslma::UsesBslmaAllocator,
491 BloombergLP::bslma::UsesBslmaAllocator<container_type>::value);
511 priority_queue(
const COMPARATOR& comparator,
const CONTAINER& container);
518 const COMPARATOR& comparator,
519 BloombergLP::bslmf::MovableRef<CONTAINER> container);
528 template <
class INPUT_ITERATOR>
537 template <
class INPUT_ITERATOR>
540 const COMPARATOR& comparator,
541 const CONTAINER& container);
549 template <
class INPUT_ITERATOR>
551 INPUT_ITERATOR first,
553 const COMPARATOR& comparator,
554 BloombergLP::bslmf::MovableRef<CONTAINER> container);
564 priority_queue(BloombergLP::bslmf::MovableRef<priority_queue> original);
574 template <
class ALLOCATOR>
579 ALLOCATOR>::type * = 0);
588 template <
class ALLOCATOR>
590 const ALLOCATOR& basicAllocator,
593 ALLOCATOR>::type * = 0);
601 template <
class ALLOCATOR>
603 const CONTAINER& container,
604 const ALLOCATOR& basicAllocator,
607 ALLOCATOR>::type * = 0);
615 template <
class ALLOCATOR>
617 BloombergLP::bslmf::MovableRef<CONTAINER> container,
618 const ALLOCATOR& basicAllocator,
621 ALLOCATOR>::type * = 0);
630 template <
class ALLOCATOR>
632 const ALLOCATOR& basicAllocator,
635 ALLOCATOR>::type * = 0);
644 template <
class ALLOCATOR>
646 BloombergLP::bslmf::MovableRef<priority_queue> original,
647 const ALLOCATOR& basicAllocator,
650 ALLOCATOR>::type * = 0);
663 template <
class t_RANGE>
668 const COMPARATOR& comparator = COMPARATOR());
669 template <
class t_RANGE,
class t_ALLOCATOR>
673 const COMPARATOR& comparator,
677 t_ALLOCATOR>::type * = 0);
678 template <
class t_RANGE,
class t_ALLOCATOR>
685 t_ALLOCATOR>::type * = 0);
698 BloombergLP::bslmf::MovableRef<priority_queue>
rhs)
707 void push(BloombergLP::bslmf::MovableRef<value_type> value);
714 template <
class t_RANGE>
718#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
723 template <
class... Args>
738 bsl::is_nothrow_swappable<CONTAINER>::value &&
739 bsl::is_nothrow_swappable<COMPARATOR>::value);
759#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
767 class = bsl::enable_if_t<!bsl::IsStdAllocator_v<CONTAINER>>
780 class = bsl::enable_if_t<bsl::uses_allocator_v<CONTAINER, ALLOCATOR>>
788 class INPUT_ITERATOR,
790 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>
800 class INPUT_ITERATOR,
804 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>
806priority_queue(INPUT_ITERATOR, INPUT_ITERATOR, COMPARATOR, CONTAINER)
809#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
812template <ranges::input_range t_RANGE,
814 std::less<ranges::range_value_t<t_RANGE>>,
815 class t_TYPE = ranges::range_value_t<t_RANGE>,
816 class = enable_if_t<!IsStdAllocator_v<t_COMPARATOR>>>
825template <ranges::input_range t_RANGE,
828 class t_TYPE = ranges::range_value_t<t_RANGE>>
829requires (!IsStdAllocator_v<t_COMPARATOR> && IsStdAllocator_v<t_ALLOCATOR>)
837template <ranges::input_range t_RANGE,
839 class t_TYPE = ranges::range_value_t<t_RANGE>,
840 class = enable_if_t<IsStdAllocator_v<t_ALLOCATOR>>>
850template <
class VALUE,
class CONTAINER,
class COMPARATOR>
864template <
class VALUE,
class CONTAINER,
class COMPARATOR>
870template <
class VALUE,
class CONTAINER,
class COMPARATOR>
873 const COMPARATOR& comparator)
878template <
class VALUE,
class CONTAINER,
class COMPARATOR>
881 const COMPARATOR& comparator,
882 const CONTAINER& container)
886 std::make_heap(
c.begin(),
c.end(),
comp);
889template <
class VALUE,
class CONTAINER,
class COMPARATOR>
892 const COMPARATOR& comparator,
893 BloombergLP::bslmf::MovableRef<CONTAINER> container)
894: c(MoveUtil::move(container))
897 std::make_heap(
c.begin(),
c.end(),
comp);
900template <
class VALUE,
class CONTAINER,
class COMPARATOR>
901template <
class INPUT_ITERATOR>
904 INPUT_ITERATOR first,
907 c.insert(c.end(), first, last);
908 std::make_heap(c.begin(), c.end(), comp);
911template <
class VALUE,
class CONTAINER,
class COMPARATOR>
912template <
class INPUT_ITERATOR>
915 INPUT_ITERATOR first,
917 const COMPARATOR& comparator,
918 const CONTAINER& container)
922 c.insert(
c.end(), first, last);
923 std::make_heap(
c.begin(),
c.end(),
comp);
926template <
class VALUE,
class CONTAINER,
class COMPARATOR>
927template <
class INPUT_ITERATOR>
930 INPUT_ITERATOR first,
932 const COMPARATOR& comparator,
933 BloombergLP::bslmf::MovableRef<CONTAINER> container)
934: c(MoveUtil::move(container))
937 c.insert(
c.end(), first, last);
938 std::make_heap(
c.begin(),
c.end(),
comp);
941template <
class VALUE,
class CONTAINER,
class COMPARATOR>
950template <
class VALUE,
class CONTAINER,
class COMPARATOR>
953 BloombergLP::bslmf::MovableRef<priority_queue> original)
954: c(MoveUtil::move(MoveUtil::access(original).c))
955, comp(MoveUtil::access(original).comp)
959template <
class VALUE,
class CONTAINER,
class COMPARATOR>
960template <
class ALLOCATOR>
963 const ALLOCATOR& basicAllocator,
972template <
class VALUE,
class CONTAINER,
class COMPARATOR>
973template <
class ALLOCATOR>
976 const COMPARATOR& comparator,
977 const ALLOCATOR& basicAllocator,
986template <
class VALUE,
class CONTAINER,
class COMPARATOR>
987template <
class ALLOCATOR>
990 const COMPARATOR& comparator,
991 const CONTAINER& container,
992 const ALLOCATOR& basicAllocator,
996: c(container, basicAllocator)
999 std::make_heap(
c.begin(),
c.end(),
comp);
1002template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1003template <
class ALLOCATOR>
1006 const COMPARATOR& comparator,
1007 BloombergLP::bslmf::MovableRef<CONTAINER> container,
1008 const ALLOCATOR& basicAllocator,
1012: c(MoveUtil::move(container), basicAllocator)
1015 std::make_heap(
c.begin(),
c.end(),
comp);
1018template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1019template <
class ALLOCATOR>
1023 const ALLOCATOR& basicAllocator,
1027: c(original.c, basicAllocator)
1028, comp(original.comp)
1032template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1033template <
class ALLOCATOR>
1036 BloombergLP::bslmf::MovableRef<priority_queue> original,
1037 const ALLOCATOR& basicAllocator,
1041: c(MoveUtil::move(MoveUtil::access(original).c), basicAllocator)
1042, comp(MoveUtil::access(original).comp)
1046template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1047template <
class t_RANGE>
1053 const COMPARATOR& comparator)
1054#ifdef BSLS_LIBRARYFEATURES_HAS_CPP23_RANGES_TO_CONTAINER
1055: c(ranges::to<CONTAINER>(std::forward<t_RANGE>(range)))
1061 std::make_heap(c.begin(), c.end(), comp);
1064template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1065template <
class t_RANGE,
class t_ALLOCATOR>
1071 const COMPARATOR& comparator,
1074 t_ALLOCATOR>::value,
1075 t_ALLOCATOR>::type *)
1076#ifdef BSLS_LIBRARYFEATURES_HAS_CPP23_RANGES_TO_CONTAINER
1077: c(ranges::to<CONTAINER>(std::forward<t_RANGE>(range),
allocator))
1083 std::make_heap(c.begin(), c.end(), comp);
1086template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1087template <
class t_RANGE,
class t_ALLOCATOR>
1095 t_ALLOCATOR>::value,
1096 t_ALLOCATOR>::type *)
1097#ifdef BSLS_LIBRARYFEATURES_HAS_CPP23_RANGES_TO_CONTAINER
1098: c(ranges::to<CONTAINER>(std::forward<t_RANGE>(range),
allocator))
1103 std::make_heap(c.begin(), c.end(), comp);
1107template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1108template <
class INPUT_ITER,
class SENTINEL>
1114 while (first != last) {
1115 c.push_back(*first);
1121template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1123priority_queue<VALUE, CONTAINER, COMPARATOR>&
1132template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1136 BloombergLP::bslmf::MovableRef<priority_queue>
rhs)
1139 c = MoveUtil::move(MoveUtil::access(
rhs).c);
1140 comp = MoveUtil::access(
rhs).comp;
1144template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1150 std::push_heap(c.begin(), c.end(), comp);
1153template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1156 BloombergLP::bslmf::MovableRef<value_type> value)
1158 c.push_back(MoveUtil::move(value));
1159 std::push_heap(c.begin(), c.end(), comp);
1162template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1163template <
class t_RANGE>
1168#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
1169 if constexpr (
requires{ c.append_range(std::forward<t_RANGE>(range)); }) {
1170 c.append_range(std::forward<t_RANGE>(range));
1173 ranges::copy(range, back_inserter(c));
1178 std::make_heap(c.begin(), c.end(), comp);
1181#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1182template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1183template <
class... Args>
1188 std::push_heap(c.begin(), c.end(), comp);
1192template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1196 std::pop_heap(c.begin(), c.end(), comp);
1200template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1204 bsl::is_nothrow_swappable<CONTAINER>::value &&
1205 bsl::is_nothrow_swappable<COMPARATOR>::value)
1207 BloombergLP::bslalg::SwapUtil::swap(&c, &other.c);
1208 BloombergLP::bslalg::SwapUtil::swap(&comp, &other.comp);
1212template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1219template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1227template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1236template <
class VALUE,
class CONTAINER,
class COMPARATOR>
1248#undef BSLSTL_PRIORITY_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE
Definition bslma_bslallocator.h:588
Definition bslstl_priorityqueue.h:446
size_type size() const
Definition bslstl_priorityqueue.h:1222
void emplace(Args &&... args)
Definition bslstl_priorityqueue.h:1185
void pop()
Definition bslstl_priorityqueue.h:1194
void swap(priority_queue &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(bsl bool empty() const
Definition bslstl_priorityqueue.h:745
COMPARATOR value_compare
Definition bslstl_priorityqueue.h:470
CONTAINER::reference reference
Definition bslstl_priorityqueue.h:472
COMPARATOR comp
Definition bslstl_priorityqueue.h:482
CONTAINER::size_type size_type
Definition bslstl_priorityqueue.h:474
priority_queue()
Definition bslstl_priorityqueue.h:866
void push_range(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
Definition bslstl_priorityqueue.h:1165
CONTAINER::const_reference const_reference
Definition bslstl_priorityqueue.h:473
BSLMF_NESTED_TRAIT_DECLARATION_IF(priority_queue, BloombergLP::bslma::UsesBslmaAllocator, BloombergLP::bslma::UsesBslmaAllocator< container_type >::value)
CONTAINER c
Definition bslstl_priorityqueue.h:478
CONTAINER::value_type value_type
Definition bslstl_priorityqueue.h:471
void push(const value_type &value)
Definition bslstl_priorityqueue.h:1146
const_reference top() const
Definition bslstl_priorityqueue.h:1230
CONTAINER container_type
Definition bslstl_priorityqueue.h:469
priority_queue & operator=(const priority_queue &rhs)
Definition bslstl_priorityqueue.h:1124
Definition bslstl_vector.h:1120
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(...)
Definition bsls_keyword.h:676
#define BSLSTL_PRIORITY_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T)
Definition bslstl_priorityqueue.h:412
Definition bdlat_valuetypefunctions.h:939
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
const from_range_t from_range
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
Definition bslmf_enableif.h:530
Definition bslstl_ranges.h:301
Definition bslmf_issame.h:146
Definition bslmf_usesallocator.h:165