FaceRecognitionLib
Tools.h
Go to the documentation of this file.
1 /* Copyright (C) 2016 Kristian Sloth Lauszus. All rights reserved.
2 
3  This software may be distributed and modified under the terms of the GNU
4  General Public License version 2 (GPL2) as published by the Free Software
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
6  this file. Please note that GPL2 Section 2[b] requires that all works based
7  on this software must also be made publicly available under the terms of
8  the GPL2 ("Copyleft").
9 
10  Contact information
11  -------------------
12 
13  Kristian Sloth Lauszus
14  Web : http://www.lauszus.com
15  e-mail : lauszus@gmail.com
16 */
17 
18 #ifndef __tools_h__
19 #define __tools_h__
20 
21 #include <numeric>
22 #include <vector>
23 
24 using namespace std;
25 
26 template<typename VectorType>
27 vector<size_t> sortIndexes(const VectorType &v) {
28  // Based on: http://stackoverflow.com/a/12399290/2175837
29  // Initialize original index locations
30  vector<size_t> idx(v.size());
31  iota(idx.begin(), idx.end(), 0);
32 
33  // Sort indexes based on comparing values in v
34  sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1] < v[i2]; });
35 
36  return idx;
37 };
38 
39 #endif
vector< size_t > sortIndexes(const VectorType &v)
Definition: Tools.h:27