[main] Added example for ranges. Unable to compile due to gcc 10 dependency. Code not tested.
Signed-off-by: coderpankaj <pankyflipkart@gmail.com>pull/1222/head
parent
3bb618bda8
commit
ea69094363
|
@ -0,0 +1,36 @@
|
||||||
|
// Content: Use of Range algorithms
|
||||||
|
// Author: Pankaj Patil
|
||||||
|
// Date: Sat, 10th July 2023
|
||||||
|
|
||||||
|
/* INCLUES */
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <ranges>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/* MAIN FUNCTION */
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
cout << "Hello World" << endl;
|
||||||
|
|
||||||
|
vector<int> v = {1, 2, 3, 3, 5, 6};
|
||||||
|
auto it = ranges::adjacent_find(v);
|
||||||
|
if (it != v.end()) {
|
||||||
|
std::cout << *it << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::vector<int> v = {1, 2, 3, 4, 5};
|
||||||
|
// int value = 3;
|
||||||
|
// auto it = std::ranges::binary_search(v, value);
|
||||||
|
// if (it != v.end()) {
|
||||||
|
// std::cout << "Found " << value << " at index " << it - v.begin() << std::endl;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile this code using : g++ -o tuple.exe testTuple.cpp
|
||||||
|
// Execute this code using : tuple.exe
|
Loading…
Reference in New Issue