Language
C++
Compiler
clang HEAD 11.0.0 (https://github.com/llvm/llvm-project.git dad6de411227faed9b15cd85d916e96e751b8528)
Options
Warnings
Boost 1.72.0
C++2a(GNU)
Boost 1.72.0
C++2a(GNU)
Boost 1.72.0
C++2a(GNU)
Boost 1.72.0
C++2a(GNU)
Boost 1.72.0
C++2a(GNU)
Boost 1.72.0
C++2a(GNU)
Boost 1.72.0
C++2a(GNU)
Boost 1.72.0
C++2a(GNU)
no pedantic
#include <algorithm>
#include <chrono>
#include <functional>
#include <iostream>
#include <vector>
#include <random>
typedef std::vector<int>::const_iterator Iterator;
namespace my {
template<class Predicate>
Iterator SequentialSearch(Iterator begin, Iterator end, Predicate pred) {
auto it = begin;
for (; it != end; ++it) {
if (pred(*it)) {
return it;
}
}
return it;
}
template<class Compare>
Iterator BinarySearch(Iterator begin, Iterator end, Compare comp) {
auto it = begin;
auto not_found = end;
while (std::distance(it, end) > 0) {
auto mid = it;
std::advance(mid, std::distance(it, end) / 2);
auto comp_result = comp(*mid);
if (comp_result == 0) {
return mid;
} else if (comp_result < 0) {
it = mid;
++it;
} else {
$ clang++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.72.0/clang-head/include -std=gnu++2a
0.0207316, 0.0207839, 0.0015202, 0.0008762 | 1000, 1000, 9
0.0440316, 0.0406313, 0.0015069, 0.0008462 | 2000, 2000, 10
0.0617135, 0.0620332, 0.0016327, 0.0010376 | 3000, 3000, 11
0.0828374, 0.0808501, 0.001471, 0.0013812 | 4000, 4000, 11
0.101499, 0.101015, 0.0015471, 0.0012261 | 5000, 5000, 12
0.124006, 0.121341, 0.0014543, 0.0009139 | 6000, 6000, 12
0.139943, 0.155956, 0.0014281, 0.0009201 | 7000, 7000, 12
0.178638, 0.165696, 0.0013954, 0.0009003 | 8000, 8000, 12
0.207956, 0.18649, 0.0014569, 0.001249 | 9000, 9000, 13
0.208243, 0.208251, 0.0014616, 0.000933 | 10000, 10000, 13
Exit Code:
0