Example #1
0
void updateContainer(Cont<T, Alloc>& cont) {
   // flip a coin to determine using emplace_back() with 80% of likelihood, or pop_back() with 20% of likelihood.
   static std::bernoulli_distribution dist(.8);
   if (cont.empty() || dist(S1::s_gen)) {
      cont.emplace_back();
   } else {
      cont.pop_back();
   }
   // and with 20% likelihood mutating 1st and last elem's std::string field
   if (!cont.empty() && !dist(S1::s_gen)) {
      cont.front().m_str.append("- foo");
      cont.back().m_str.append("- bar");
   }
}
Example #2
0
	iterator insert(value_type&& val) {
		if (container.empty()) {
			return container.insert(detail::adl_cend(container), val);
		}
		auto elementgreaterthanorequalto = std::lower_bound(detail::adl_cbegin(container), detail::adl_cend(container), val, std::ref(predicate));
		return container.insert(elementgreaterthanorequalto, std::move(val));
	}
Example #3
0
	iterator emplace(Tn&&... argn) {
		if (container.empty()) {
			return container.insert(detail::adl_cend(container), std::forward<Tn>(argn)...);
		}
		auto elementgreaterthanorequalto = std::lower_bound(detail::adl_cbegin(container), detail::adl_cend(container), val, std::ref(predicate));
		return container.emplace(elementgreaterthanorequalto, std::forward<Tn>(argn)...);
	}
Example #4
0
	iterator emplace(Tn&&... argn) {
		if (container.empty()) {
			return container.emplace(cend(), std::forward<Tn>(argn)...);
		}
		auto elementgreaterthanorequalto = std::lower_bound(cbegin(), cend(), val, std::ref(compare_predicate));
		return container.emplace(elementgreaterthanorequalto, std::forward<Tn>(argn)...);
	}
Example #5
0
	iterator insert(value_type&& val) {
		if (container.empty()) {
			return container.insert(cend(), val);
		}
		auto elementgreaterthanorequalto = std::lower_bound(cbegin(), cend(), val, std::ref(compare_predicate));
		return container.insert(elementgreaterthanorequalto, std::move(val));
	}
Example #6
0
 // return shared pointer to value - which if set to nullptr,
 // indicates container was empty at the time of the call.
 inline std::shared_ptr<T> try_pop() {
     std::lock_guard<std::mutex> lock(mut);
     if (data_queue.empty()) {
         return std::shared_ptr<T>();
     } else {
         auto res = std::move(front_or_top(data_queue));
         data_queue.pop();
         return std::move(res);
     }
 }
Example #7
0
 // return value in specified reference indicating whether
 // value successfully returned or not
 inline bool try_pop(std::shared_ptr<T>& rValue) {
     std::lock_guard<std::mutex> lock(mut);
     if (data_queue.empty()) {
         rValue.reset();
         return false;
     } else {
         rValue = std::move(front_or_top(data_queue));
         data_queue.pop();
         return true;
     }
 }
Example #8
0
 // wait for non empty lambda condition before returning shared pointer to value
 inline std::shared_ptr<T> wait_and_pop() {
     std::unique_lock<std::mutex> lock(mut);
     data_cond.wait(lock, [this]{
         return !data_queue.empty() || shutdownFlag;
     });
     if (!shutdownFlag) {
         auto res = std::move(front_or_top(data_queue));
         data_queue.pop();
         return std::move(res);
     }
     return nullptr;
 }
Example #9
0
	iterator find(K&& k) {
		auto e = end();
		if (container.empty()) {
			return e;
		}
		auto elementgreaterthanorequalto = std::lower_bound(begin(), e, k, std::ref(compare_predicate));
		if (elementgreaterthanorequalto == e) {
			return elementgreaterthanorequalto;
		}
		decltype(auto) elem = *elementgreaterthanorequalto;
		if (equality_predicate(std::forward<K>(k), elem)) {
			return elementgreaterthanorequalto;
		}
		return e;
	}
	bool empty() const {
		return elements.empty();
	}
inline bool check_empty(const Cont &c)
{
  return c.empty() && c.size() == 0 && c.begin() == c.end();
}
Example #12
0
 bool empty() const {       // return whether the stack is empty
     return elems.empty();
 }
Example #13
0
 // thread safe method to check if the queue is empty
 // note that if it is empty
 inline bool empty() const {
     std::lock_guard<std::mutex> lock(mut);
     return data_queue.empty();
 }