online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <vector> #include <iterator> #include <algorithm> namespace nonstd { template<class ForwardIt, class T, class Comp> ForwardIt binary_search(ForwardIt first, ForwardIt last, const T & value, Comp comp) { auto low = std::lower_bound(first, last, value, comp); auto up = std::upper_bound(first, last, value, comp); if (low != up) return low; return last; } } int main() { std::vector<int> data = { 3, 7, 5, 8, 7, 2, 9, 4, 1, 7, 6, 0 }; std::sort(std::begin(data), std::end(data), std::greater<int>()); copy(std::begin(data), std::end(data), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n'; int val = 7; auto ans = nonstd::binary_search(std::begin(data), std::end(data), val, std::greater<int>()); if (ans != std::end(data)) std::cout << *ans << " found at index " << std::distance(std::begin(data), ans) << '\n'; else std::cout << val << " not found\n"; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue