Created
July 11, 2016 08:44
-
-
Save wreulicke/4cac93fea650ed662b8f9ee88304b56f to your computer and use it in GitHub Desktop.
C++ memo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <initializer_list> | |
#include <type_traits> | |
#include <algorithm> | |
using namespace std; | |
template <typename T,size_t n=0> | |
vector<enable_if_t<is_arithmetic<T>::value,T>> data(){ | |
size_t x=n; | |
vector<T> v; | |
while(x--)v.insert(v.begin(),x); | |
return v; | |
} | |
int main(){ | |
vector<int> v1=data<int,50>(); | |
auto it1 = upper_bound(v1.begin(), v1.end(), 9); | |
cout << "pos = " << (it1 - v1.begin()) << endl; | |
vector<int> v=data<int,5>(); | |
auto it = upper_bound(v.begin(), v.end(), 9); | |
cout << "pos = " << (it - v.begin()) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment